Code preparation

Package installation.

Classified by type of package

library(rmarkdown)             # Documentation generation
library(officer)              # Manipulating Microsoft Word documents
library(flextable)            # Creating formatted tables in Microsoft Word documents
library(tableHTML)            # Creating tables in HTML format
library(gtsummary)            # Creating summary tables
library(here)                 # Dealing with file path

# ---- dealing with data
library(dplyr)                # Data manipulation and transformation
library(tidyr)                # Data tidying
library(DataExplorer)         # Exploratory data analysis
library(compareGroups)        # Comparing groups
library(psych)                # Psychological statistics and data manipulation
library(Hmisc)                # Miscellaneous functions for data analysis

# ---- Survival analysis
library(poptrend)             # Calculating p-trend in survival analysis
library(survival)             # Survival analysis
library(survivalAnalysis)     # Survival analysis functions
library(survminer)            # Drawing survival curves
library(adjustedCurves)       # Plotting adjusted survival curves
library(pammtools)            # Plotting adjusted survival curves
library(survIDINRI)           # Make reclassification and discrimination 
library(glmnet)               # Regularized regression models
library(olsrr)                # Variable selection at its best !

# ---- Graphics
library(ggplot2)              # Data visualization
library(mctest)               # Multiple hypothesis testing --> assess colinearity between continuous variable
library(corrplot)             # Visualizing correlation matrices
library(fmsb)                 # Creating radar plots
library(concreg)              # Plotting adjusted survival curves
library(ggpubr)               # Associating the risk table when plotting


# ---- My functions (located in the scrits/functions_R file)
source(here("functions_R","CoxPredictScore.R"))
source(here("functions_R","createSurvivalPlot.R"))
source(here("functions_R","process_data.R"))
source(here("functions_R","extract_model_stats.R"))
source(here("functions_R","forest_function.R"))
source(here("functions_R","uni_multi_function.R")) # function that does the table

Data Download (RData).

Using the data.management_ICM_Tradi_V4 results directly saved in RData. * df_all : 6,082 patients * df_LGE : 3,591 patients * df_MACE : 1,500 patients with the informations

load(file = here("data","df_all.RData"))
load(file = here("data","df_LGE.RData"))
load(file = here("data","df_MACE.RData"))

Creation of differents files

library(here)

# Get today's date and format it as a string in the required format
date_suffix <- format(Sys.Date(), "%Y-%m-%d")

# Define the directory paths including the date with specified prefixes
tables_date_dir <- here("outputs", "tables", paste0("Tab-", date_suffix))
figures_date_dir <- here("outputs", "figures", paste0("Fig-", date_suffix))

# Check and create the "tables" date-specific directory if it doesn't exist
if (!dir.exists(tables_date_dir)) {
  dir.create(tables_date_dir, recursive = TRUE)
  message("Directory created: ", tables_date_dir)
} else {
  message("Directory already exists: ", tables_date_dir)
}
## Directory already exists: /Users/alexandreunger/Documents/PROJECTS/ICM/ICM_tradi/RProject_ICM_tradi/outputs/tables/Tab-2024-06-21
# Check and create the "figures" date-specific directory if it doesn't exist
if (!dir.exists(figures_date_dir)) {
  dir.create(figures_date_dir, recursive = TRUE)
  message("Directory created: ", figures_date_dir)
} else {
  message("Directory already exists: ", figures_date_dir)
}
## Directory already exists: /Users/alexandreunger/Documents/PROJECTS/ICM/ICM_tradi/RProject_ICM_tradi/outputs/figures/Fig-2024-06-21
# Save the directory paths for later use in the script
tables_output_dir <- tables_date_dir
figures_output_dir <- figures_date_dir

All population (N=6,081)

Descriptive

Tab1-descr-all-LGE_presence

Descr_table = createTable(compareGroups(
  CMR_LGE_ischemic_presence ~ 
    demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
    CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
    
    history_med_MI  + history_coronary_procedure + history_interv_PCI + 
    history_interv_CABG + med_periph_atheroma + history_stroke + 
    med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
    clini_cardiac_rythm + 
    
   outcome_revascularisation_90days +
    
    CMR_LVEF + CMR_LVEDV + 
    CMR_LVESV + CMR_LV_mass + CMR_RV_dysfunction + 
    
    CMR_LGE_presence_ischemic_and_midwall +
    
    CMR_LGE_ischemic_presence + 
    CMR_LGE_ischemic_extent_count +
    CMR_LGE_ischemic_extent_categ +
    CMR_LGE_ischemic_transmurality +
    CMR_LGE_ischemic_location_4 +
    
    CMR_LGE_ischemic_anterior + 
    CMR_LGE_ischemic_septal +
    CMR_LGE_ischemic_inferior +
    CMR_LGE_ischemic_lateral +
    CMR_LGE_ischemic_Apical +
    
    CMR_LGE_midwall_presence +
    CMR_LGE_midwall_extent_count + 
    CMR_LGE_midwall_extent_categ +
    CMR_LGE_midwall_location_3 + 
    CMR_LGE_midwall_location_4 +
    CMR_LGE_midwall_anterior +
    CMR_LGE_midwall_septal +
    CMR_LGE_midwall_inferior +
    CMR_LGE_midwall_lateral +
    CMR_LGE_midwall_apical,
  data= df_all,
  method = 1, conf.level = 0.995),
  hide.no = "No",
  show.all=T, show.p.overall = T) 

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `CMR_LGE_ischemic_presence’
[ALL] No_ischemic_LGE Presence_of_ischemic_LGE p.overall
N=6082 N=2491 N=3591
demo_age 64.5 (11.8) 64.2 (11.9) 64.8 (11.7) 0.069
demo_gender 4419 (72.7%) 1740 (69.9%) 2679 (74.6%) <0.001
demo_BMI 27.7 (5.33) 27.7 (5.21) 27.7 (5.41) 0.893
CV_risk_diabete 2309 (38.0%) 863 (34.6%) 1446 (40.3%) <0.001
CV_risk_HTA 3144 (51.7%) 1240 (49.8%) 1904 (53.0%) 0.014
CV_risk_obesity 1687 (27.7%) 700 (28.1%) 987 (27.5%) 0.618
CV_risk_dyslipidemia 3005 (49.4%) 1214 (48.7%) 1791 (49.9%) 0.397
CV_risk_Smoking 1285 (21.1%) 519 (20.8%) 766 (21.3%) 0.664
history_med_MI 2354 (38.7%) 967 (38.8%) 1387 (38.6%) 0.899
history_coronary_procedure 5394 (88.7%) 2227 (89.4%) 3167 (88.2%) 0.155
history_interv_PCI 380 (6.25%) 123 (4.94%) 257 (7.16%) 0.001
history_interv_CABG 5085 (83.6%) 2132 (85.6%) 2953 (82.2%) 0.001
med_periph_atheroma 344 (5.66%) 130 (5.22%) 214 (5.96%) 0.241
history_stroke 186 (3.06%) 69 (2.77%) 117 (3.26%) 0.312
med_pacemaker 41 (0.67%) 17 (0.68%) 24 (0.67%) 1.000
med_CKD 121 (1.99%) 52 (2.09%) 69 (1.92%) 0.717
history_hospit_HF 368 (6.05%) 140 (5.62%) 228 (6.35%) 0.264
history_AFib 453 (7.45%) 185 (7.43%) 268 (7.46%) 0.997
clini_NYHA 753 (12.4%) 293 (11.8%) 460 (12.8%) 0.238
clini_cardiac_rythm 426 (7.00%) 177 (7.11%) 249 (6.93%) 0.836
outcome_revascularisation_90days 2773 (45.6%) 0 (0.00%) 2773 (77.2%) 0.000
CMR_LVEF 43.7 (5.70) 43.9 (5.50) 43.6 (5.83) 0.057
CMR_LVEDV 103 (21.5) 103 (21.5) 103 (21.5) 0.791
CMR_LVESV 58.6 (17.8) 58.5 (17.8) 58.7 (17.7) 0.674
CMR_LV_mass 91.0 (19.5) 91.0 (19.4) 91.1 (19.5) 0.823
CMR_RV_dysfunction 218 (3.58%) 71 (2.85%) 147 (4.09%) 0.013
CMR_LGE_presence_ischemic_and_midwall 354 (5.82%) 0 (0.00%) 354 (9.86%) <0.001
CMR_LGE_ischemic_presence: 0.000
No_ischemic_LGE 2491 (41.0%) 2491 (100%) 0 (0.00%)
Presence_of_ischemic_LGE 3591 (59.0%) 0 (0.00%) 3591 (100%)
CMR_LGE_ischemic_extent_count 1.83 (1.96) 0.00 (0.00) 3.10 (1.60) 0.000
CMR_LGE_ischemic_extent_categ: 0.000
A_No_ischemic_LGE 2491 (41.0%) 2491 (100%) 0 (0.00%)
B_1_2_segments 1392 (22.9%) 0 (0.00%) 1392 (38.8%)
C_3_5_segments 1953 (32.1%) 0 (0.00%) 1953 (54.4%)
D_more6_segments 246 (4.04%) 0 (0.00%) 246 (6.85%)
CMR_LGE_ischemic_transmurality: 0.000
A_No_ischemic_LGE 2491 (41.0%) 2491 (100%) 0 (0.00%)
B_Subendocardial<50% 1698 (27.9%) 0 (0.00%) 1698 (47.3%)
C_Subendocardial≥50% 1549 (25.5%) 0 (0.00%) 1549 (43.1%)
D_Transmural 344 (5.66%) 0 (0.00%) 344 (9.58%)
CMR_LGE_ischemic_location_4: 0.000
A_No_ischemic_LGE 2491 (41.0%) 2491 (100%) 0 (0.00%)
B_Neither_anterior_nor_septal 2662 (43.8%) 0 (0.00%) 2662 (74.1%)
C_Anterior_without_septal 422 (6.94%) 0 (0.00%) 422 (11.8%)
D_Septal 507 (8.34%) 0 (0.00%) 507 (14.1%)
CMR_LGE_ischemic_anterior 786 (12.9%) 0 (0.00%) 786 (21.9%) <0.001
CMR_LGE_ischemic_septal 507 (8.34%) 0 (0.00%) 507 (14.1%) <0.001
CMR_LGE_ischemic_inferior 1214 (20.0%) 0 (0.00%) 1214 (33.8%) <0.001
CMR_LGE_ischemic_lateral 1195 (19.6%) 0 (0.00%) 1195 (33.3%) <0.001
CMR_LGE_ischemic_Apical 1168 (19.2%) 0 (0.00%) 1168 (32.5%) <0.001
CMR_LGE_midwall_presence: <0.001
A_No_midwall_LGE 5380 (88.5%) 2143 (86.0%) 3237 (90.1%)
B_Presence_of_midwall_LGE 702 (11.5%) 348 (14.0%) 354 (9.86%)
CMR_LGE_midwall_extent_count 0.13 (0.39) 0.15 (0.39) 0.12 (0.38) 0.001
CMR_LGE_midwall_extent_categ: <0.001
None 5380 (88.5%) 2143 (86.0%) 3237 (90.1%)
Low_=1 610 (10.0%) 321 (12.9%) 289 (8.05%)
High_>1 92 (1.51%) 27 (1.08%) 65 (1.81%)
CMR_LGE_midwall_location_3: <0.001
No_midwall_LGE 5380 (88.5%) 2143 (86.0%) 3237 (90.1%)
Midwall_LGE_not_at_risk 471 (7.74%) 240 (9.63%) 231 (6.43%)
At_risk_midwall_LGE_(septal_and/or_lateral) 231 (3.80%) 108 (4.34%) 123 (3.43%)
CMR_LGE_midwall_location_4: <0.001
No_midwall_LGE 5380 (88.5%) 2143 (86.0%) 3237 (90.1%)
Midwall_LGE_not_at_risk 471 (7.74%) 240 (9.63%) 231 (6.43%)
Lateral_midwall_LGE 118 (1.94%) 53 (2.13%) 65 (1.81%)
Septal_Midwall_LGE 113 (1.86%) 55 (2.21%) 58 (1.62%)
CMR_LGE_midwall_anterior 140 (2.30%) 41 (1.65%) 99 (2.76%) 0.006
CMR_LGE_midwall_septal 113 (1.86%) 55 (2.21%) 58 (1.62%) 0.113
CMR_LGE_midwall_inferior 212 (3.49%) 112 (4.50%) 100 (2.78%) <0.001
CMR_LGE_midwall_lateral 124 (2.04%) 54 (2.17%) 70 (1.95%) 0.617
CMR_LGE_midwall_apical 146 (2.40%) 91 (3.65%) 55 (1.53%) <0.001
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab1-descr-all-LGE_presence-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Tab2-descr-all-center

Descr_table = createTable(compareGroups(
    demo_center ~ 
    demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
    CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
    
    history_med_MI  + history_coronary_procedure + history_interv_PCI + 
    history_interv_CABG + med_periph_atheroma + history_stroke + 
    med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
    clini_cardiac_rythm + 
    
   outcome_revascularisation_90days +
    
    CMR_LVEF + CMR_LVEDV + 
    CMR_LVESV + CMR_LV_mass + CMR_RV_dysfunction + 
    
    CMR_LGE_presence_ischemic_and_midwall +
    
    CMR_LGE_ischemic_presence + 
    CMR_LGE_ischemic_extent_count +
    CMR_LGE_ischemic_extent_categ +
    CMR_LGE_ischemic_transmurality +
    CMR_LGE_ischemic_location_4 +
    
    CMR_LGE_ischemic_anterior + 
    CMR_LGE_ischemic_septal +
    CMR_LGE_ischemic_inferior +
    CMR_LGE_ischemic_lateral +
    CMR_LGE_ischemic_Apical +
    
    CMR_LGE_midwall_presence +
    CMR_LGE_midwall_extent_count + 
    CMR_LGE_midwall_extent_categ +
    CMR_LGE_midwall_location_3 + 
    CMR_LGE_midwall_location_4 +
    CMR_LGE_midwall_anterior +
    CMR_LGE_midwall_septal +
    CMR_LGE_midwall_inferior +
    CMR_LGE_midwall_lateral +
    CMR_LGE_midwall_apical,
  data= df_all,
  method = 1, conf.level = 0.995),
  hide.no = "No",
  show.all=T, show.p.overall = T) 

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `demo_center’
[ALL] ICPS Lariboisiere p.overall
N=6082 N=5214 N=868
demo_age 64.5 (11.8) 64.4 (11.9) 65.3 (11.4) 0.026
demo_gender 4419 (72.7%) 3738 (71.7%) 681 (78.5%) <0.001
demo_BMI 27.7 (5.33) 27.7 (5.34) 27.8 (5.24) 0.658
CV_risk_diabete 2309 (38.0%) 1850 (35.5%) 459 (52.9%) <0.001
CV_risk_HTA 3144 (51.7%) 2698 (51.7%) 446 (51.4%) 0.872
CV_risk_obesity 1687 (27.7%) 1452 (27.8%) 235 (27.1%) 0.667
CV_risk_dyslipidemia 3005 (49.4%) 2571 (49.3%) 434 (50.0%) 0.734
CV_risk_Smoking 1285 (21.1%) 1092 (20.9%) 193 (22.2%) 0.413
history_med_MI 2354 (38.7%) 1929 (37.0%) 425 (49.0%) <0.001
history_coronary_procedure 5394 (88.7%) 4657 (89.3%) 737 (84.9%) <0.001
history_interv_PCI 380 (6.25%) 278 (5.33%) 102 (11.8%) <0.001
history_interv_CABG 5085 (83.6%) 4439 (85.1%) 646 (74.4%) <0.001
med_periph_atheroma 344 (5.66%) 294 (5.64%) 50 (5.76%) 0.949
history_stroke 186 (3.06%) 160 (3.07%) 26 (3.00%) 0.992
med_pacemaker 41 (0.67%) 37 (0.71%) 4 (0.46%) 0.545
med_CKD 121 (1.99%) 111 (2.13%) 10 (1.15%) 0.076
history_hospit_HF 368 (6.05%) 306 (5.87%) 62 (7.14%) 0.167
history_AFib 453 (7.45%) 395 (7.58%) 58 (6.68%) 0.390
clini_NYHA 753 (12.4%) 645 (12.4%) 108 (12.4%) 0.997
clini_cardiac_rythm 426 (7.00%) 367 (7.04%) 59 (6.80%) 0.852
outcome_revascularisation_90days 2773 (45.6%) 2235 (42.9%) 538 (62.0%) <0.001
CMR_LVEF 43.7 (5.70) 43.8 (5.53) 43.1 (6.61) 0.003
CMR_LVEDV 103 (21.5) 103 (20.9) 104 (25.0) 0.189
CMR_LVESV 58.6 (17.8) 58.4 (17.3) 59.9 (20.3) 0.035
CMR_LV_mass 91.0 (19.5) 91.0 (19.4) 91.6 (19.8) 0.399
CMR_RV_dysfunction 218 (3.58%) 174 (3.34%) 44 (5.07%) 0.015
CMR_LGE_presence_ischemic_and_midwall 354 (5.82%) 307 (5.89%) 47 (5.41%) 0.636
CMR_LGE_ischemic_presence: <0.001
No_ischemic_LGE 2491 (41.0%) 2314 (44.4%) 177 (20.4%)
Presence_of_ischemic_LGE 3591 (59.0%) 2900 (55.6%) 691 (79.6%)
CMR_LGE_ischemic_extent_count 1.83 (1.96) 1.74 (1.96) 2.37 (1.85) <0.001
CMR_LGE_ischemic_extent_categ: <0.001
A_No_ischemic_LGE 2491 (41.0%) 2314 (44.4%) 177 (20.4%)
B_1_2_segments 1392 (22.9%) 1102 (21.1%) 290 (33.4%)
C_3_5_segments 1953 (32.1%) 1596 (30.6%) 357 (41.1%)
D_more6_segments 246 (4.04%) 202 (3.87%) 44 (5.07%)
CMR_LGE_ischemic_transmurality: <0.001
A_No_ischemic_LGE 2491 (41.0%) 2314 (44.4%) 177 (20.4%)
B_Subendocardial<50% 1698 (27.9%) 1355 (26.0%) 343 (39.5%)
C_Subendocardial≥50% 1549 (25.5%) 1268 (24.3%) 281 (32.4%)
D_Transmural 344 (5.66%) 277 (5.31%) 67 (7.72%)
CMR_LGE_ischemic_location_4: <0.001
A_No_ischemic_LGE 2491 (41.0%) 2314 (44.4%) 177 (20.4%)
B_Neither_anterior_nor_septal 2662 (43.8%) 2136 (41.0%) 526 (60.6%)
C_Anterior_without_septal 422 (6.94%) 351 (6.73%) 71 (8.18%)
D_Septal 507 (8.34%) 413 (7.92%) 94 (10.8%)
CMR_LGE_ischemic_anterior 786 (12.9%) 651 (12.5%) 135 (15.6%) 0.015
CMR_LGE_ischemic_septal 507 (8.34%) 413 (7.92%) 94 (10.8%) 0.005
CMR_LGE_ischemic_inferior 1214 (20.0%) 970 (18.6%) 244 (28.1%) <0.001
CMR_LGE_ischemic_lateral 1195 (19.6%) 974 (18.7%) 221 (25.5%) <0.001
CMR_LGE_ischemic_Apical 1168 (19.2%) 960 (18.4%) 208 (24.0%) <0.001
CMR_LGE_midwall_presence: <0.001
A_No_midwall_LGE 5380 (88.5%) 4581 (87.9%) 799 (92.1%)
B_Presence_of_midwall_LGE 702 (11.5%) 633 (12.1%) 69 (7.95%)
CMR_LGE_midwall_extent_count 0.13 (0.39) 0.14 (0.39) 0.10 (0.35) 0.001
CMR_LGE_midwall_extent_categ: 0.001
None 5380 (88.5%) 4581 (87.9%) 799 (92.1%)
Low_=1 610 (10.0%) 553 (10.6%) 57 (6.57%)
High_>1 92 (1.51%) 80 (1.53%) 12 (1.38%)
CMR_LGE_midwall_location_3: 0.002
No_midwall_LGE 5380 (88.5%) 4581 (87.9%) 799 (92.1%)
Midwall_LGE_not_at_risk 471 (7.74%) 426 (8.17%) 45 (5.18%)
At_risk_midwall_LGE_(septal_and/or_lateral) 231 (3.80%) 207 (3.97%) 24 (2.76%)
CMR_LGE_midwall_location_4: 0.004
No_midwall_LGE 5380 (88.5%) 4581 (87.9%) 799 (92.1%)
Midwall_LGE_not_at_risk 471 (7.74%) 426 (8.17%) 45 (5.18%)
Lateral_midwall_LGE 118 (1.94%) 104 (1.99%) 14 (1.61%)
Septal_Midwall_LGE 113 (1.86%) 103 (1.98%) 10 (1.15%)
CMR_LGE_midwall_anterior 140 (2.30%) 132 (2.53%) 8 (0.92%) 0.005
CMR_LGE_midwall_septal 113 (1.86%) 103 (1.98%) 10 (1.15%) 0.127
CMR_LGE_midwall_inferior 212 (3.49%) 191 (3.66%) 21 (2.42%) 0.080
CMR_LGE_midwall_lateral 124 (2.04%) 110 (2.11%) 14 (1.61%) 0.407
CMR_LGE_midwall_apical 146 (2.40%) 127 (2.44%) 19 (2.19%) 0.749
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab2-descr-all-center-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Tab3-descr-all-death

df_selected <- df_all %>% mutate(
  outcome_death = as.factor(outcome_death),
  outcome_MACE = as.factor(outcome_MACE ),
  outcome_MACE_CV_death = as.factor(outcome_MACE_CV_death),
  outcome_MACE_NonFatal_MI = as.factor(outcome_MACE_NonFatal_MI)
)

Descr_table = createTable(compareGroups(
    outcome_death ~ 
      
    outcome_revascularisation_90days + outcome_death + outcome_MACE + outcome_MACE_CV_death + outcome_MACE_NonFatal_MI +
      
    demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
    CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
    
    history_med_MI  + history_coronary_procedure + history_interv_PCI + 
    history_interv_CABG + med_periph_atheroma + history_stroke + 
    med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
    clini_cardiac_rythm + 
    
   outcome_revascularisation_90days +
    
    CMR_LVEF + CMR_LVEDV + 
    CMR_LVESV + CMR_LV_mass + CMR_RV_dysfunction + 
    
    CMR_LGE_presence_ischemic_and_midwall +
    
    CMR_LGE_ischemic_presence + 
    CMR_LGE_ischemic_extent_count +
    CMR_LGE_ischemic_extent_categ +
    CMR_LGE_ischemic_transmurality +
    CMR_LGE_ischemic_location_4 +
    
    CMR_LGE_ischemic_anterior + 
    CMR_LGE_ischemic_septal +
    CMR_LGE_ischemic_inferior +
    CMR_LGE_ischemic_lateral +
    CMR_LGE_ischemic_Apical +
    
    CMR_LGE_midwall_presence +
    CMR_LGE_midwall_extent_count + 
    CMR_LGE_midwall_extent_categ +
    CMR_LGE_midwall_location_3 + 
    CMR_LGE_midwall_location_4 +
    CMR_LGE_midwall_anterior +
    CMR_LGE_midwall_septal +
    CMR_LGE_midwall_inferior +
    CMR_LGE_midwall_lateral +
    CMR_LGE_midwall_apical,
  data= df_selected,
  method = 1, conf.level = 0.995),
  hide.no = "No",
  show.all=T, show.p.overall = T) 

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `outcome_death’
[ALL] 0 1 p.overall
N=6082 N=5430 N=652
outcome_revascularisation_90days 2773 (45.6%) 2525 (46.5%) 248 (38.0%) <0.001
outcome_death: 0.000
0 5430 (89.3%) 5430 (100%) 0 (0.00%)
1 652 (10.7%) 0 (0.00%) 652 (100%)
outcome_MACE: <0.001
0 1227 (81.8%) 1207 (94.8%) 20 (8.81%)
1 273 (18.2%) 66 (5.18%) 207 (91.2%)
outcome_MACE_CV_death: <0.001
0 1286 (86.5%) 1269 (100%) 17 (7.83%)
1 200 (13.5%) 0 (0.00%) 200 (92.2%)
outcome_MACE_NonFatal_MI: 0.302
0 1414 (95.2%) 1204 (94.9%) 210 (96.8%)
1 72 (4.85%) 65 (5.12%) 7 (3.23%)
demo_age 64.5 (11.8) 64.1 (11.8) 68.3 (11.3) <0.001
demo_gender 4419 (72.7%) 3843 (70.8%) 576 (88.3%) <0.001
demo_BMI 27.7 (5.33) 27.7 (5.30) 27.8 (5.57) 0.553
CV_risk_diabete 2309 (38.0%) 1945 (35.8%) 364 (55.8%) <0.001
CV_risk_HTA 3144 (51.7%) 2817 (51.9%) 327 (50.2%) 0.429
CV_risk_obesity 1687 (27.7%) 1509 (27.8%) 178 (27.3%) 0.828
CV_risk_dyslipidemia 3005 (49.4%) 2677 (49.3%) 328 (50.3%) 0.657
CV_risk_Smoking 1285 (21.1%) 1137 (20.9%) 148 (22.7%) 0.322
history_med_MI 2354 (38.7%) 2090 (38.5%) 264 (40.5%) 0.343
history_coronary_procedure 5394 (88.7%) 4817 (88.7%) 577 (88.5%) 0.922
history_interv_PCI 380 (6.25%) 310 (5.71%) 70 (10.7%) <0.001
history_interv_CABG 5085 (83.6%) 4566 (84.1%) 519 (79.6%) 0.004
med_periph_atheroma 344 (5.66%) 276 (5.08%) 68 (10.4%) <0.001
history_stroke 186 (3.06%) 150 (2.76%) 36 (5.52%) <0.001
med_pacemaker 41 (0.67%) 38 (0.70%) 3 (0.46%) 0.618
med_CKD 121 (1.99%) 84 (1.55%) 37 (5.67%) <0.001
history_hospit_HF 368 (6.05%) 286 (5.27%) 82 (12.6%) <0.001
history_AFib 453 (7.45%) 382 (7.03%) 71 (10.9%) 0.001
clini_NYHA 753 (12.4%) 668 (12.3%) 85 (13.0%) 0.635
clini_cardiac_rythm 426 (7.00%) 368 (6.78%) 58 (8.90%) 0.055
outcome_revascularisation_90days 2773 (45.6%) 2525 (46.5%) 248 (38.0%) <0.001
CMR_LVEF 43.7 (5.70) 43.9 (5.58) 42.2 (6.38) <0.001
CMR_LVEDV 103 (21.5) 103 (21.2) 106 (24.0) 0.002
CMR_LVESV 58.6 (17.8) 58.2 (17.5) 61.9 (19.6) <0.001
CMR_LV_mass 91.0 (19.5) 91.1 (19.5) 90.9 (19.5) 0.870
CMR_RV_dysfunction 218 (3.58%) 153 (2.82%) 65 (9.97%) <0.001
CMR_LGE_presence_ischemic_and_midwall 354 (5.82%) 223 (4.11%) 131 (20.1%) <0.001
CMR_LGE_ischemic_presence: <0.001
No_ischemic_LGE 2491 (41.0%) 2388 (44.0%) 103 (15.8%)
Presence_of_ischemic_LGE 3591 (59.0%) 3042 (56.0%) 549 (84.2%)
CMR_LGE_ischemic_extent_count 1.83 (1.96) 1.53 (1.66) 4.30 (2.44) <0.001
CMR_LGE_ischemic_extent_categ: 0.000
A_No_ischemic_LGE 2491 (41.0%) 2388 (44.0%) 103 (15.8%)
B_1_2_segments 1392 (22.9%) 1369 (25.2%) 23 (3.53%)
C_3_5_segments 1953 (32.1%) 1659 (30.6%) 294 (45.1%)
D_more6_segments 246 (4.04%) 14 (0.26%) 232 (35.6%)
CMR_LGE_ischemic_transmurality: <0.001
A_No_ischemic_LGE 2491 (41.0%) 2388 (44.0%) 103 (15.8%)
B_Subendocardial<50% 1698 (27.9%) 1619 (29.8%) 79 (12.1%)
C_Subendocardial≥50% 1549 (25.5%) 1290 (23.8%) 259 (39.7%)
D_Transmural 344 (5.66%) 133 (2.45%) 211 (32.4%)
CMR_LGE_ischemic_location_4: 0.000
A_No_ischemic_LGE 2491 (41.0%) 2388 (44.0%) 103 (15.8%)
B_Neither_anterior_nor_septal 2662 (43.8%) 2563 (47.2%) 99 (15.2%)
C_Anterior_without_septal 422 (6.94%) 317 (5.84%) 105 (16.1%)
D_Septal 507 (8.34%) 162 (2.98%) 345 (52.9%)
CMR_LGE_ischemic_anterior 786 (12.9%) 384 (7.07%) 402 (61.7%) 0.000
CMR_LGE_ischemic_septal 507 (8.34%) 162 (2.98%) 345 (52.9%) 0.000
CMR_LGE_ischemic_inferior 1214 (20.0%) 1097 (20.2%) 117 (17.9%) 0.190
CMR_LGE_ischemic_lateral 1195 (19.6%) 966 (17.8%) 229 (35.1%) <0.001
CMR_LGE_ischemic_Apical 1168 (19.2%) 875 (16.1%) 293 (44.9%) <0.001
CMR_LGE_midwall_presence: <0.001
A_No_midwall_LGE 5380 (88.5%) 4901 (90.3%) 479 (73.5%)
B_Presence_of_midwall_LGE 702 (11.5%) 529 (9.74%) 173 (26.5%)
CMR_LGE_midwall_extent_count 0.13 (0.39) 0.10 (0.31) 0.39 (0.71) <0.001
CMR_LGE_midwall_extent_categ: <0.001
None 5380 (88.5%) 4901 (90.3%) 479 (73.5%)
Low_=1 610 (10.0%) 510 (9.39%) 100 (15.3%)
High_>1 92 (1.51%) 19 (0.35%) 73 (11.2%)
CMR_LGE_midwall_location_3: <0.001
No_midwall_LGE 5380 (88.5%) 4901 (90.3%) 479 (73.5%)
Midwall_LGE_not_at_risk 471 (7.74%) 406 (7.48%) 65 (9.97%)
At_risk_midwall_LGE_(septal_and/or_lateral) 231 (3.80%) 123 (2.27%) 108 (16.6%)
CMR_LGE_midwall_location_4: <0.001
No_midwall_LGE 5380 (88.5%) 4901 (90.3%) 479 (73.5%)
Midwall_LGE_not_at_risk 471 (7.74%) 406 (7.48%) 65 (9.97%)
Lateral_midwall_LGE 118 (1.94%) 64 (1.18%) 54 (8.28%)
Septal_Midwall_LGE 113 (1.86%) 59 (1.09%) 54 (8.28%)
CMR_LGE_midwall_anterior 140 (2.30%) 113 (2.08%) 27 (4.14%) 0.001
CMR_LGE_midwall_septal 113 (1.86%) 59 (1.09%) 54 (8.28%) <0.001
CMR_LGE_midwall_inferior 212 (3.49%) 166 (3.06%) 46 (7.06%) <0.001
CMR_LGE_midwall_lateral 124 (2.04%) 64 (1.18%) 60 (9.20%) <0.001
CMR_LGE_midwall_apical 146 (2.40%) 132 (2.43%) 14 (2.15%) 0.755
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab3-descr-all-death-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Survival

Tab4-univ-all-death

df_selected <- df_all %>%
  mutate(
    surv.event = Surv(
      time = outcome_FU_time_death,
      event = outcome_death
    ),
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVEDV_5 = CMR_LVEDV/10,
    CMR_LVESV_5 = CMR_LVESV/10
  )

Descr_table = createTable(compareGroups(
  surv.event ~ 
    demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
    CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
    
    history_med_MI  + history_coronary_procedure + history_interv_PCI + 
    history_interv_CABG + med_periph_atheroma + history_stroke + 
    med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
    clini_cardiac_rythm + 
    
   outcome_revascularisation_90days +
    
    CMR_LVEF_5 + CMR_LVEDV_5 + 
    CMR_LVESV_5 + CMR_LV_mass + CMR_RV_dysfunction + 
    
    CMR_LGE_presence_ischemic_and_midwall +
    
    CMR_LGE_ischemic_presence + 
    CMR_LGE_ischemic_extent_count +
    CMR_LGE_ischemic_extent_categ +
    CMR_LGE_ischemic_transmurality +
    CMR_LGE_ischemic_location_4 +
    
    CMR_LGE_ischemic_anterior + 
    CMR_LGE_ischemic_septal +
    CMR_LGE_ischemic_inferior +
    CMR_LGE_ischemic_lateral +
    CMR_LGE_ischemic_Apical +
    
    CMR_LGE_midwall_presence +
    CMR_LGE_midwall_extent_count + 
    CMR_LGE_midwall_extent_categ +
    CMR_LGE_midwall_location_3 + 
    CMR_LGE_midwall_location_4 +
    CMR_LGE_midwall_anterior +
    CMR_LGE_midwall_septal +
    CMR_LGE_midwall_inferior +
    CMR_LGE_midwall_lateral +
    CMR_LGE_midwall_apical,
  data= df_selected,
  method = 1, conf.level = 0.995),
  hide.no = "No",
  show.ratio =T, show.p.ratio =  T) 

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `surv.event’
No event Event HR p.ratio p.overall
N=5430 N=652
demo_age 64.1 (11.8) 68.3 (11.3) 1.03 [1.02;1.04] <0.001 <0.001
demo_gender 3843 (70.8%) 576 (88.3%) 2.83 [2.01;3.98] <0.001 0.000
demo_BMI 27.7 (5.30) 27.8 (5.57) 1.01 [0.98;1.03] 0.490 0.490
CV_risk_diabete 1945 (35.8%) 364 (55.8%) 2.09 [1.68;2.61] <0.001 0.000
CV_risk_HTA 2817 (51.9%) 327 (50.2%) 0.92 [0.74;1.14] 0.277 0.276
CV_risk_obesity 1509 (27.8%) 178 (27.3%) 0.98 [0.76;1.25] 0.804 0.805
CV_risk_dyslipidemia 2677 (49.3%) 328 (50.3%) 1.04 [0.83;1.29] 0.637 0.634
CV_risk_Smoking 1137 (20.9%) 148 (22.7%) 1.08 [0.83;1.41] 0.401 0.402
history_med_MI 2090 (38.5%) 264 (40.5%) 1.08 [0.86;1.35] 0.342 0.341
history_coronary_procedure 4817 (88.7%) 577 (88.5%) 0.98 [0.70;1.39] 0.878 0.879
history_interv_PCI 310 (5.71%) 70 (10.7%) 1.74 [1.21;2.49] <0.001 <0.001
history_interv_CABG 4566 (84.1%) 519 (79.6%) 0.78 [0.59;1.03] 0.011 0.011
med_periph_atheroma 276 (5.08%) 68 (10.4%) 1.97 [1.38;2.82] <0.001 <0.001
history_stroke 150 (2.76%) 36 (5.52%) 1.92 [1.18;3.11] <0.001 <0.001
med_pacemaker 38 (0.70%) 3 (0.46%) 0.71 [0.14;3.61] 0.556 0.555
med_CKD 84 (1.55%) 37 (5.67%) 3.98 [2.48;6.41] <0.001 0.000
history_hospit_HF 286 (5.27%) 82 (12.6%) 2.32 [1.66;3.23] <0.001 <0.001
history_AFib 382 (7.03%) 71 (10.9%) 1.60 [1.12;2.28] <0.001 <0.001
clini_NYHA 668 (12.3%) 85 (13.0%) 1.02 [0.73;1.41] 0.885 0.884
clini_cardiac_rythm 368 (6.78%) 58 (8.90%) 1.34 [0.91;1.97] 0.036 0.034
outcome_revascularisation_90days 2525 (46.5%) 248 (38.0%) 0.73 [0.58;0.91] <0.001 <0.001
CMR_LVEF_5 8.79 (1.12) 8.43 (1.28) 0.82 [0.75;0.89] <0.001 <0.001
CMR_LVEDV_5 10.3 (2.12) 10.6 (2.40) 1.05 [1.01;1.10] 0.002 0.002
CMR_LVESV_5 5.82 (1.75) 6.19 (1.96) 1.09 [1.03;1.14] <0.001 <0.001
CMR_LV_mass 91.1 (19.5) 90.9 (19.5) 1.00 [0.99;1.01] 0.772 0.772
CMR_RV_dysfunction 153 (2.82%) 65 (9.97%) 3.32 [2.30;4.79] <0.001 0.000
CMR_LGE_presence_ischemic_and_midwall 223 (4.11%) 131 (20.1%) 4.44 [3.37;5.85] <0.001 0.000
CMR_LGE_ischemic_presence: 0.000
No_ischemic_LGE 2388 (44.0%) 103 (15.8%) Ref. Ref.
Presence_of_ischemic_LGE 3042 (56.0%) 549 (84.2%) 3.76 [2.78;5.08] <0.001
CMR_LGE_ischemic_extent_count 1.53 (1.66) 4.30 (2.44) 1.70 [1.62;1.79] <0.001 <0.001
CMR_LGE_ischemic_extent_categ: 0.000
A_No_ischemic_LGE 2388 (44.0%) 103 (15.8%) Ref. Ref.
B_1_2_segments 1369 (25.2%) 23 (3.53%) 0.41 [0.21;0.78] <0.001
C_3_5_segments 1659 (30.6%) 294 (45.1%) 3.64 [2.64;5.02] <0.001
D_more6_segments 14 (0.26%) 232 (35.6%) 27.7 [19.9;38.7] <0.001
CMR_LGE_ischemic_transmurality: 0.000
A_No_ischemic_LGE 2388 (44.0%) 103 (15.8%) Ref. Ref.
B_Subendocardial<50% 1619 (29.8%) 79 (12.1%) 1.14 [0.75;1.73] 0.386
C_Subendocardial≥50% 1290 (23.8%) 259 (39.7%) 4.06 [2.93;5.63] <0.001
D_Transmural 133 (2.45%) 211 (32.4%) 16.7 [11.9;23.4] <0.001
CMR_LGE_ischemic_location_4: 0.000
A_No_ischemic_LGE 2388 (44.0%) 103 (15.8%) Ref. Ref.
B_Neither_anterior_nor_septal 2563 (47.2%) 99 (15.2%) 0.89 [0.60;1.32] 0.395
C_Anterior_without_septal 317 (5.84%) 105 (16.1%) 6.40 [4.34;9.45] <0.001
D_Septal 162 (2.98%) 345 (52.9%) 19.4 [14.1;26.6] <0.001
CMR_LGE_ischemic_anterior 384 (7.07%) 402 (61.7%) 12.4 [9.87;15.5] <0.001 0.000
CMR_LGE_ischemic_septal 162 (2.98%) 345 (52.9%) 14.6 [11.7;18.2] <0.001 0.000
CMR_LGE_ischemic_inferior 1097 (20.2%) 117 (17.9%) 0.88 [0.66;1.17] 0.218 0.216
CMR_LGE_ischemic_lateral 966 (17.8%) 229 (35.1%) 2.20 [1.75;2.77] <0.001 0.000
CMR_LGE_ischemic_Apical 875 (16.1%) 293 (44.9%) 3.54 [2.84;4.42] <0.001 0.000
CMR_LGE_midwall_presence: 0.000
A_No_midwall_LGE 4901 (90.3%) 479 (73.5%) Ref. Ref.
B_Presence_of_midwall_LGE 529 (9.74%) 173 (26.5%) 2.85 [2.22;3.66] <0.001
CMR_LGE_midwall_extent_count 0.10 (0.31) 0.39 (0.71) 2.63 [2.24;3.10] <0.001 <0.001
CMR_LGE_midwall_extent_categ: 0.000
None 4901 (90.3%) 479 (73.5%) Ref. Ref.
Low_=1 510 (9.39%) 100 (15.3%) 1.88 [1.38;2.56] <0.001
High_>1 19 (0.35%) 73 (11.2%) 10.3 [7.21;14.7] <0.001
CMR_LGE_midwall_location_3: 0.000
No_midwall_LGE 4901 (90.3%) 479 (73.5%) Ref. Ref.
Midwall_LGE_not_at_risk 406 (7.48%) 65 (9.97%) 1.53 [1.06;2.22] 0.001
At_risk_midwall_LGE_(septal_and/or_lateral) 123 (2.27%) 108 (16.6%) 5.94 [4.39;8.02] <0.001
CMR_LGE_midwall_location_4: 0.000
No_midwall_LGE 4901 (90.3%) 479 (73.5%) Ref. Ref.
Midwall_LGE_not_at_risk 406 (7.48%) 65 (9.97%) 1.53 [1.05;2.22] 0.001
Lateral_midwall_LGE 64 (1.18%) 54 (8.28%) 6.03 [4.03;9.02] <0.001
Septal_Midwall_LGE 59 (1.09%) 54 (8.28%) 5.84 [3.89;8.79] <0.001
CMR_LGE_midwall_anterior 113 (2.08%) 27 (4.14%) 1.62 [0.93;2.83] 0.015 0.012
CMR_LGE_midwall_septal 59 (1.09%) 54 (8.28%) 5.16 [3.45;7.74] <0.001 0.000
CMR_LGE_midwall_inferior 166 (3.06%) 46 (7.06%) 2.46 [1.60;3.78] <0.001 <0.001
CMR_LGE_midwall_lateral 64 (1.18%) 60 (9.20%) 5.75 [3.93;8.42] <0.001 0.000
CMR_LGE_midwall_apical 132 (2.43%) 14 (2.15%) 0.79 [0.37;1.69] 0.382 0.370
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab4-univ-all-death-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Tab5-multi_tradi-all-death

df <- df_all %>% mutate(
  event = outcome_death,
  time = outcome_FU_time_death,
  CMR_LVEF_5 = CMR_LVEF/5
) %>% select(
  event, time,
  demo_age, demo_gender, demo_BMI , CV_risk_diabete , CV_risk_Smoking , CV_risk_dyslipidemia ,  history_hospit_HF, history_AFib, med_CKD, history_med_MI , CMR_LVEF_5, CMR_LGE_ischemic_presence) %>% droplevels()

#### TABLE 

## Model 1
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LVEF_5))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 1", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 1
Coefficients_CI HR_CI p_value
demo_age 0.03 ( 0.02 - 0.04 ) 1.03 ( 1.02 - 1.04 ) <0.001
demo_genderYes 1.00 ( 0.66 - 1.35 ) 2.73 ( 1.93 - 3.86 ) <0.001
demo_BMI 0.00 ( -0.02 - 0.03 ) 1.00 ( 0.98 - 1.03 ) 0.855
CV_risk_diabeteYes 0.64 ( 0.41 - 0.87 ) 1.91 ( 1.51 - 2.40 ) <0.001
CV_risk_SmokingYes 0.25 ( -0.03 - 0.52 ) 1.28 ( 0.97 - 1.69 ) 0.011
CV_risk_dyslipidemiaYes -0.08 ( -0.30 - 0.15 ) 0.93 ( 0.74 - 1.16 ) 0.338
history_hospit_HFYes 0.51 ( 0.15 - 0.86 ) 1.66 ( 1.16 - 2.37 ) <0.001
history_AFibYes 0.03 ( -0.33 - 0.40 ) 1.04 ( 0.72 - 1.49 ) 0.791
med_CKDYes 0.98 ( 0.49 - 1.47 ) 2.66 ( 1.62 - 4.35 ) <0.001
history_med_MIYes 0.03 ( -0.20 - 0.26 ) 1.03 ( 0.82 - 1.30 ) 0.705
CMR_LVEF_5 -0.10 ( -0.19 - -0.01 ) 0.90 ( 0.83 - 0.99 ) 0.001
## Model 2
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_presence))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 2", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 2
Coefficients_CI HR_CI p_value
demo_age 0.03 ( 0.02 - 0.04 ) 1.03 ( 1.02 - 1.04 ) <0.001
demo_genderYes 0.96 ( 0.61 - 1.31 ) 2.61 ( 1.84 - 3.69 ) <0.001
demo_BMI 0.00 ( -0.02 - 0.03 ) 1.00 ( 0.98 - 1.03 ) 0.614
CV_risk_diabeteYes 0.58 ( 0.35 - 0.81 ) 1.79 ( 1.42 - 2.26 ) <0.001
CV_risk_SmokingYes 0.25 ( -0.03 - 0.52 ) 1.28 ( 0.97 - 1.69 ) 0.012
CV_risk_dyslipidemiaYes -0.07 ( -0.29 - 0.16 ) 0.94 ( 0.75 - 1.17 ) 0.411
history_hospit_HFYes 0.49 ( 0.13 - 0.84 ) 1.63 ( 1.14 - 2.32 ) <0.001
history_AFibYes 0.04 ( -0.33 - 0.40 ) 1.04 ( 0.72 - 1.50 ) 0.762
med_CKDYes 0.98 ( 0.49 - 1.47 ) 2.67 ( 1.63 - 4.37 ) <0.001
history_med_MIYes 0.05 ( -0.18 - 0.28 ) 1.05 ( 0.83 - 1.32 ) 0.560
CMR_LVEF_5 -0.09 ( -0.18 - -0.00 ) 0.92 ( 0.84 - 1.00 ) 0.005
CMR_LGE_ischemic_presencePresence_of_ischemic_LGE 1.24 ( 0.94 - 1.54 ) 3.45 ( 2.55 - 4.67 ) <0.001
# Table uni multi 
table <- uni_multi_function(
  df = df, 
  event = "event",
  time = "time", 
  var_base = c("demo_age", "demo_gender" , "demo_BMI" , "CV_risk_diabete" , "CV_risk_Smoking" , "CV_risk_dyslipidemia" ,  "history_hospit_HF", "history_AFib" , "med_CKD" , "history_med_MI" , "CMR_LVEF_5"), 
  var_added = c("CMR_LGE_ischemic_presence"))

# export in html
knitr::kable(table, caption = "Model 2 - LGE presence - All population", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 2 - LGE presence - All population
Variable Univariate_Analysis model_multi_1 model_multi_2
demo_age 1.03 (1.02-1.04), p=0.000 1.03 (1.02-1.04), p=0.000 1.03 (1.02-1.04), p=0.000
demo_genderYes 2.83 (2.01-3.98), p=0.000 2.73 (1.93-3.86), p=0.000 2.61 (1.84-3.69), p=0.000
demo_BMI 1.01 (0.98-1.03), p=0.490 1.00 (0.98-1.03), p=0.855 1.00 (0.98-1.03), p=0.614
CV_risk_diabeteYes 2.09 (1.68-2.61), p=0.000 1.91 (1.51-2.40), p=0.000 1.79 (1.42-2.26), p=0.000
CV_risk_SmokingYes 1.08 (0.83-1.41), p=0.401 1.28 (0.97-1.69), p=0.011 1.28 (0.97-1.69), p=0.012
CV_risk_dyslipidemiaYes 1.04 (0.83-1.29), p=0.637 0.93 (0.74-1.16), p=0.338 0.94 (0.75-1.17), p=0.411
history_hospit_HFYes 2.32 (1.66-3.23), p=0.000 1.66 (1.16-2.37), p=0.000 1.63 (1.14-2.32), p=0.000
history_AFibYes 1.60 (1.12-2.28), p=0.000 1.04 (0.72-1.49), p=0.791 1.04 (0.72-1.50), p=0.762
med_CKDYes 3.98 (2.48-6.41), p=0.000 2.66 (1.62-4.35), p=0.000 2.67 (1.63-4.37), p=0.000
history_med_MIYes 1.08 (0.86-1.35), p=0.342 1.03 (0.82-1.30), p=0.705 1.05 (0.83-1.32), p=0.560
CMR_LVEF_5 0.82 (0.75-0.89), p=0.000 0.90 (0.83-0.99), p=0.001 0.92 (0.84-1.00), p=0.005
CMR_LGE_ischemic_presencePresence_of_ischemic_LGE 3.76 (2.78-5.08), p=0.000 NA 3.45 (2.55-4.67), p=0.000
# Export in word
ft <- flextable(table)
ft <- set_table_properties(ft, layout = "autofit")
doc <- read_docx() %>%
  body_add_par("Model 3 - LGE presence in all pop (N=6,082)", style = "heading 1") %>%
  body_add_flextable(ft)
print(doc, target = here(tables_output_dir,paste0("Tab5-multi_tradi-all-death-",Sys.Date(), ".docx")))

Tab6-incr-all-death

var1 <- c("demo_age", "demo_gender" , "demo_BMI" , "CV_risk_diabete" , "CV_risk_Smoking" , "CV_risk_dyslipidemia" ,  "history_hospit_HF", "history_AFib" , "med_CKD" , "history_med_MI" , "CMR_LVEF")
var2 <- c(var1, "CMR_LGE_ischemic_presence")

df <- df_all %>% mutate(
  time = outcome_FU_time_death,
  event = outcome_death
)%>% droplevels()

# MODEL 1
results.model1 <- CoxPredictScore(derivation = df, validation = df,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var1, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model1$model_stats
## NULL
results.model1$derivation$auc
## [1] "0.7 [0.67-0.73]"
# MODEL 2
results.model2 <- CoxPredictScore(derivation = df, validation = df,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var2, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model2$model_stats
## NULL
results.model2$derivation$auc
## [1] "0.75 [0.72-0.77]"
roc.test(results.model1$roc_derivation$roc_obj, results.model2$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model1$roc_derivation$roc_obj and results.model2$roc_derivation$roc_obj
## Z = -5.614, p-value = 1.976e-08
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.06561281 -0.03165491
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.7021060   0.7507399

Figures

Fig1-all-KM-LGE_presence

# Data parameters
results <- createSurvivalPlot(
  data = df_all,
  compared_with = "CMR_LGE_ischemic_presence",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  my_colors = c("#25A26B","#FF002B"),
  confint_choosen = 0.995,
  mytitle = "Fig1: LGE presence (all pop = 6,082)"
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ CMR_LGE_ischemic_presence"
results$HR
##                  HR_CI p_value
## 1 3.76 ( 2.78 - 5.08 )  <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig1-all-KM-LGE_presence_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig1-all-KM-LGE_presence_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

Fig2-all-KM-LGE_presence_multi

# Data parameters
df_selected <- df_all %>%
  select(
    outcome_FU_time_death, outcome_death,
    CMR_LGE_ischemic_presence,
    demo_age, demo_gender , demo_BMI , CV_risk_diabete , CV_risk_Smoking , CV_risk_dyslipidemia ,  history_hospit_HF , history_AFib , med_CKD , history_med_MI , CMR_LVEF
  )  %>%
  mutate(
    outcome_FU_time_death = outcome_FU_time_death/12
  ) %>% filter(
    outcome_FU_time_death <= 9
  )

summary(df_selected$outcome_FU_time_death)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.08333 5.33333 6.58333 6.44798 7.83333 9.00000
# statistics parameters
confint_choosen = 0.995
P_vizu = TRUE # To check log rank for all KM graphs

# Graphics viz
legend_title <- c("Ischemic LGE")
my_legends <- c("Absence of LGE","Presence of LGE")
mytitle <- c("Fig 1C - LGE MULTI - ALL (N=6082)")
my_colors <- c("#25A26B","#FF002B")
size_font = 12
ylim_choosen = c(0.5,1) 
xlim_choosen = c(0,13)

#### ------------------------ ####
library(riskRegression)
model <- coxph(formula = Surv(outcome_FU_time_death, outcome_death) ~ CMR_LGE_ischemic_presence + demo_age+ demo_gender + demo_BMI + CV_risk_diabete + CV_risk_Smoking + CV_risk_dyslipidemia +  history_hospit_HF + history_AFib + med_CKD + history_med_MI + CMR_LVEF, data = df_selected, x = TRUE)


adjsurv <- adjustedsurv(data=df_selected, # utilisation de ce filtre pour ne pas avoir l'ensemble de la courbe
                        variable="CMR_LGE_ischemic_presence",
                        ev_time="outcome_FU_time_death",
                        event="outcome_death",
                        method="direct",
                        outcome_model=model,
                        conf_int=TRUE,
                        conf_level = 0.995,
                        colors = TRUE,
                        custom_colors = my_colors,
                        ggtheme = theme_bw())


# plot with confidence intervals
gg <- plot(adjsurv, 
     main = mytitle,
     legend.title = NULL,
     legend.position = "none",
     conf_int = TRUE,
     censoring_ind = "lines",
     xlab = "years of follow-up",
     ylab = "Adjusted survival probability",
     xlim = c(0, 12),
     ylim = c(0.5, 1),
     custom_colors = my_colors,
     ggtheme = theme_bw()) +
  scale_x_continuous(breaks = seq(0, 12, 2),
                     labels = seq(0, 12, 2)) +
  theme(axis.text = element_text(size = size_font),  # Adjust the font size of the axis labels
        axis.title = element_text(size = size_font + 2),  # Adjust the font size of the axis titles
        axis.line = element_line(size = 0.1), # reduced size of axis
        legend.text = element_text(size = size_font + 4),  # Adjust the font size of the legend text
        legend.title = element_text(size = size_font + 6),  # Adjust the font size of the legend title
        panel.border = element_rect(color = "black", fill = NA, size = 0.3),
        panel.background = element_rect(fill = "white"),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank())

gg

ggsave(
  filename = here(figures_output_dir, paste0("Fig2-all-KM-LGE_presence_multi-", Sys.Date(),".png")), 
  plot = gg, width = 10, height = 6, units = "in", dpi = 600)

Fig3-all-KM-LGE_FEVG_plot

# Data parameters
df_selected <- df_all %>%
  mutate(
    FEVG_LGE = case_when(
      CMR_LGE_ischemic_presence == "No_ischemic_LGE" & CMR_LVEF > 40 ~ "A LGE - ; FEVG ≥ 40",
      CMR_LGE_ischemic_presence == "No_ischemic_LGE" & CMR_LVEF <= 40 ~ "B LGE - ; FEVG < 40",
      CMR_LGE_ischemic_presence == "Presence_of_ischemic_LGE" & CMR_LVEF > 40 ~ "C LGE + ; FEVG ≥ 40",
      CMR_LGE_ischemic_presence == "Presence_of_ischemic_LGE" & CMR_LVEF <= 40 ~ "D LGE + ; FEVG < 40",
      TRUE ~ NA_character_
    )
  )

# Data parameters
results <- createSurvivalPlot(
  data = df_selected,
  compared_with = "FEVG_LGE",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  my_colors = c("#25A26B","#4292C6","#FF002B","#2C3E50"),
  confint_choosen = 0.995,
  mytitle = "Fig4: LGE type (all pop = 6,082)"
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ FEVG_LGE"
results$HR
##                                            HR_CI p_value
## FEVG_LGEB LGE - ; FEVG < 40 1.12 ( 0.61 - 2.06 )   0.596
## FEVG_LGEC LGE + ; FEVG ≥ 40 3.22 ( 2.24 - 4.63 )  <0.001
## FEVG_LGED LGE + ; FEVG < 40 5.61 ( 3.84 - 8.19 )  <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig3-all-KM-LGE_FEVG_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig3-all-KM-LGE_FEVG_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

Fig4-all-KM-LGE_type

# Data parameters
results <- createSurvivalPlot(
  data = df_all,
  compared_with = "CMR_LGE_type",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  my_colors = c("#25A26B","#4292C6","#FF002B","#2C3E50"),
  confint_choosen = 0.995,
  mytitle = "Fig4: LGE type (all pop = 6,082)"
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ CMR_LGE_type"
results$HR
##                                                                HR_CI p_value
## CMR_LGE_typeExclusive_midwall_LGE_presence      4.18 ( 2.38 - 7.33 )  <0.001
## CMR_LGE_typeExclusive_ischemic_LGE_presence     4.57 ( 3.11 - 6.72 )  <0.001
## CMR_LGE_typeischemic_and_midwall_LGE_presence 14.26 ( 9.22 - 22.06 )  <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig4-all-KM-LGE_type_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig4-all-KM-LGE_type_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

KM Revascularization

Fig5-all-KM-revasc - in modif

results <- createSurvivalPlot(
  data = df_all,
  compared_with = "outcome_revascularisation_90days",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  confint_choosen = 0.995,
  legend_title = "Fig revasc pop = 6,082"
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ outcome_revascularisation_90days"
results$HR
##                  HR_CI p_value
## 1 0.73 ( 0.58 - 0.91 )  <0.001
results$ggsurv

ggsave(
  filename = here(figures_output_dir, paste0("Fig5-all-KM-revasc_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig5-all-KM-revasc_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

Fig6-all-KM-revasc_viability - in modif

# Modification of the dataset
df_selected <- df_all %>%
  mutate(
  CMR_LGE_Viable = case_when(
    CMR_LGE_ischemic_transmurality == "B_Subendocardial<50%" ~ 1,
    CMR_LGE_ischemic_transmurality == "C_Subendocardial≥50%" | CMR_LGE_ischemic_transmurality == "D_Transmural" ~ 2,
    TRUE ~ 3),
  CMR_LGE_Viable = factor(
    CMR_LGE_Viable, levels = c(1,2,3), labels = c("Viable","NonViable","NoLGE")
  ),
  CMR_LGE_Viable_Revasc = case_when(
    CMR_LGE_Viable == "Viable" & outcome_revascularisation_90days == "Yes" ~ 1,
    CMR_LGE_Viable == "Viable" & outcome_revascularisation_90days == "No" ~ 2,
    CMR_LGE_Viable == "NonViable" & outcome_revascularisation_90days == "Yes" ~ 3,
    CMR_LGE_Viable == "NonViable" & outcome_revascularisation_90days == "No" ~ 4,
    TRUE ~ 0),
  CMR_LGE_Viable_Revasc = factor(
    CMR_LGE_Viable_Revasc, levels = c(0,1,2,3,4), labels = c("No_LGE","Viable_Revasc","viable_NonRevasc","NonViable_Revasc","NonViable_NonRevasc")
  )
  )

results <- createSurvivalPlot(
  data = df_selected,
  compared_with = "CMR_LGE_Viable_Revasc",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  confint_choosen = 0.995,
  legend_title = "Fig revasc pop = 6,082",
  my_colors = c("#006400", "darkblue", "#FF0000", "#8B4513", "#000000"),
  show.CI = FALSE
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ CMR_LGE_Viable_Revasc"
results$HR
##                                                           HR_CI p_value
## CMR_LGE_Viable_RevascViable_Revasc         0.89 ( 0.56 - 1.42 )   0.480
## CMR_LGE_Viable_Revascviable_NonRevasc      3.20 ( 1.69 - 6.05 )  <0.001
## CMR_LGE_Viable_RevascNonViable_Revasc      3.69 ( 2.62 - 5.20 )  <0.001
## CMR_LGE_Viable_RevascNonViable_NonRevasc 11.48 ( 8.30 - 15.88 )  <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig6-all-KM-revasc_viability_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig6-all-KM-revasc_viability_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

Fig7-all-corrplot

# Select specific columns for correlation analysis
df_selected <- df_LGE %>%
  mutate_if(is.factor, ~ as.numeric(.)) %>%
  select(demo_NIP:CMR_LGE_ischemic_presence) %>%
  select(-outcome_death, -outcome_FU_time_death, -CMR_LGE_presence_ischemic_or_midwall, -demo_NIP, -demo_center)

# Calculate the correlation matrix and round the values
correlation_matrix <- cor(df_selected)

# Set the threshold for identifying highly correlated features
threshold <- 0.7

# Find highly correlated feature pairs
correlation_pairs <- which(correlation_matrix > threshold & correlation_matrix < 1, arr.ind = TRUE)

# Extract the names and correlation values of the most collinear features
most_collinear_features <- data.frame(
  Feature1 = rownames(correlation_matrix)[correlation_pairs[, 1]],
  Feature2 = colnames(correlation_matrix)[correlation_pairs[, 2]],
  Correlation_Value = correlation_matrix[correlation_pairs]
)
# Sort by correlation value in descending order
most_collinear_features <- most_collinear_features[order(-most_collinear_features$Correlation_Value), ]
print(most_collinear_features)
##              Feature1            Feature2 Correlation_Value
## 7           CMR_LVESV           CMR_LVEDV         0.9486931
## 8           CMR_LVEDV           CMR_LVESV         0.9486931
## 1        history_AFib clini_cardiac_rythm         0.9486426
## 6 clini_cardiac_rythm        history_AFib         0.9486426
## 2            demo_BMI         demo_weight         0.8593656
## 3         demo_weight            demo_BMI         0.8593656
## 4     CV_risk_obesity            demo_BMI         0.7552200
## 5            demo_BMI     CV_risk_obesity         0.7552200
# Create a color palette for the plot
color_palette <- colorRampPalette(c("blue", "black", "red"))(50)

# Create an attractive correlation plot
correlation_matrix <- cor(df_selected[, unique(most_collinear_features$Feature1)])

corrplot(correlation_matrix,
         method = "number",   # Display correlation values
         type = "upper",      # Display only the upper triangle
         col = color_palette, # Set the color palette
         tl.cex = 0.8,        # Adjust text label size
         tl.col = "black",    # Set text label color
         cl.ratio = 0.2,      # Adjust the space for the color legend
         number.cex = 0.7,    # Adjust correlation value size
         addCoef.col = "black" # Set coefficient color
)

correlation_matrix <- cor(df_selected)

corrplot(correlation_matrix,
         method = "color",
         type = "full",
         tl.col = "black",
         addCoefasPercent = FALSE # Remove value display
)

corrplot(correlation_matrix,
                      method = "color",
                      type = "full",
                      tl.col = "black",
                      addCoefasPercent = FALSE)  # Removes value display

# Saving the plot
# # Note: 'corr_plot' does not need to be assigned or used with 'plot = c' in ggsave
# ggsave(
#   filename = here("outputs", "figures", paste0("Fig7-all-corrplot-", Sys.Date(), ".png")),
#   plot = corr_plot,  # Saves the last plot
#   width = 10,
#   height = 3,
#   units = "in",
#   dpi = 600
# )

LGE population (N=3,591)

Survival

Tab7-univ-LGE-death

df_selected <- df_LGE %>%
  mutate(
    surv.event = Surv(
      time = outcome_FU_time_death,
      event = outcome_death
    ),
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVEDV_5 = CMR_LVEDV/10,
    CMR_LVESV_5 = CMR_LVESV/10
  )

Descr_table = createTable(compareGroups(
  surv.event ~ 
    demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
    CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
    
    history_med_MI  + history_coronary_procedure + history_interv_PCI + 
    history_interv_CABG + med_periph_atheroma + history_stroke + 
    med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
    clini_cardiac_rythm + 
    
   outcome_revascularisation_90days +
    
    CMR_LVEF_5 + CMR_LVEDV_5 + 
    CMR_LVESV_5 + CMR_LV_mass + CMR_RV_dysfunction + 
    
    CMR_LGE_presence_ischemic_and_midwall +
    
    CMR_LGE_ischemic_presence + 
    CMR_LGE_ischemic_extent_count +
    CMR_LGE_ischemic_extent_categ +
    CMR_LGE_ischemic_transmurality +
    CMR_LGE_ischemic_location_4 +
    
    CMR_LGE_ischemic_anterior + 
    CMR_LGE_ischemic_septal +
    CMR_LGE_ischemic_inferior +
    CMR_LGE_ischemic_lateral +
    CMR_LGE_ischemic_Apical +
    
    CMR_LGE_midwall_presence +
    CMR_LGE_midwall_extent_count + 
    CMR_LGE_midwall_extent_categ +
    CMR_LGE_midwall_location_3 + 
    CMR_LGE_midwall_location_4 +
    CMR_LGE_midwall_anterior +
    CMR_LGE_midwall_septal +
    CMR_LGE_midwall_inferior +
    CMR_LGE_midwall_lateral +
    CMR_LGE_midwall_apical,
  data= df_selected,
  method = 1, conf.level = 0.995),
  hide.no = "No",
  show.ratio=T, show.p.ratio = T) 

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `surv.event’
No event Event HR p.ratio p.overall
N=3042 N=549
demo_age 64.1 (11.7) 68.3 (11.3) 1.03 [1.02;1.04] <0.001 <0.001
demo_gender 2194 (72.1%) 485 (88.3%) 2.64 [1.82;3.84] <0.001 <0.001
demo_BMI 27.7 (5.37) 27.8 (5.65) 1.00 [0.98;1.03] 0.600 0.600
CV_risk_diabete 1137 (37.4%) 309 (56.3%) 1.96 [1.54;2.50] <0.001 <0.001
CV_risk_HTA 1627 (53.5%) 277 (50.5%) 0.90 [0.71;1.14] 0.215 0.215
CV_risk_obesity 836 (27.5%) 151 (27.5%) 1.01 [0.77;1.33] 0.892 0.888
CV_risk_dyslipidemia 1505 (49.5%) 286 (52.1%) 1.11 [0.87;1.41] 0.224 0.222
CV_risk_Smoking 639 (21.0%) 127 (23.1%) 1.10 [0.83;1.47] 0.328 0.329
history_med_MI 1167 (38.4%) 220 (40.1%) 1.07 [0.83;1.36] 0.463 0.465
history_coronary_procedure 2679 (88.1%) 488 (88.9%) 1.06 [0.73;1.56] 0.649 0.648
history_interv_PCI 198 (6.51%) 59 (10.7%) 1.57 [1.06;2.33] 0.001 0.001
history_interv_CABG 2515 (82.7%) 438 (79.8%) 0.84 [0.62;1.13] 0.100 0.098
med_periph_atheroma 156 (5.13%) 58 (10.6%) 1.99 [1.35;2.94] <0.001 <0.001
history_stroke 85 (2.79%) 32 (5.83%) 1.99 [1.20;3.33] <0.001 <0.001
med_pacemaker 21 (0.69%) 3 (0.55%) 0.83 [0.16;4.20] 0.741 0.741
med_CKD 39 (1.28%) 30 (5.46%) 3.69 [2.18;6.26] <0.001 <0.001
history_hospit_HF 155 (5.10%) 73 (13.3%) 2.39 [1.68;3.41] <0.001 <0.001
history_AFib 207 (6.80%) 61 (11.1%) 1.61 [1.10;2.36] <0.001 <0.001
clini_NYHA 385 (12.7%) 75 (13.7%) 1.01 [0.71;1.44] 0.919 0.918
clini_cardiac_rythm 197 (6.48%) 52 (9.47%) 1.42 [0.94;2.14] 0.017 0.016
outcome_revascularisation_90days 2525 (83.0%) 248 (45.2%) 0.23 [0.18;0.29] <0.001 0.000
CMR_LVEF_5 8.78 (1.14) 8.40 (1.27) 0.82 [0.75;0.89] <0.001 <0.001
CMR_LVEDV_5 10.2 (2.11) 10.6 (2.38) 1.05 [1.00;1.11] 0.003 0.003
CMR_LVESV_5 5.81 (1.74) 6.20 (1.92) 1.09 [1.03;1.16] <0.001 <0.001
CMR_LV_mass 91.1 (19.6) 90.8 (19.5) 1.00 [0.99;1.00] 0.573 0.573
CMR_RV_dysfunction 89 (2.93%) 58 (10.6%) 3.15 [2.13;4.65] <0.001 0.000
CMR_LGE_presence_ischemic_and_midwall 223 (7.33%) 131 (23.9%) 3.13 [2.36;4.15] <0.001 0.000
CMR_LGE_ischemic_presence: Presence_of_ischemic_LGE 3042 (100%) 549 (100%) Ref. Ref. .
CMR_LGE_ischemic_extent_count 2.74 (1.28) 5.11 (1.72) 1.90 [1.78;2.02] <0.001 <0.001
CMR_LGE_ischemic_extent_categ: 0.000
B_1_2_segments 1369 (45.0%) 23 (4.19%) Ref. Ref.
C_3_5_segments 1659 (54.5%) 294 (53.6%) 8.92 [4.86;16.4] <0.001
D_more6_segments 14 (0.46%) 232 (42.3%) 68.3 [37.0;126] <0.001
CMR_LGE_ischemic_transmurality: 0.000
B_Subendocardial<50% 1619 (53.2%) 79 (14.4%) Ref. Ref.
C_Subendocardial≥50% 1290 (42.4%) 259 (47.2%) 3.57 [2.49;5.12] <0.001
D_Transmural 133 (4.37%) 211 (38.4%) 14.7 [10.2;21.3] <0.001
CMR_LGE_ischemic_location_4: 0.000
B_Neither_anterior_nor_septal 2563 (84.3%) 99 (18.0%) Ref. Ref.
C_Anterior_without_septal 317 (10.4%) 105 (19.1%) 7.22 [4.87;10.7] <0.001
D_Septal 162 (5.33%) 345 (62.8%) 21.9 [15.9;30.2] <0.001
CMR_LGE_ischemic_anterior 384 (12.6%) 402 (73.2%) 11.2 [8.56;14.7] <0.001 0.000
CMR_LGE_ischemic_septal 162 (5.33%) 345 (62.8%) 12.2 [9.51;15.6] <0.001 0.000
CMR_LGE_ischemic_inferior 1097 (36.1%) 117 (21.3%) 0.53 [0.39;0.71] <0.001 <0.001
CMR_LGE_ischemic_lateral 966 (31.8%) 229 (41.7%) 1.41 [1.11;1.80] <0.001 <0.001
CMR_LGE_ischemic_Apical 875 (28.8%) 293 (53.4%) 2.44 [1.92;3.10] <0.001 0.000
CMR_LGE_midwall_presence: 0.000
A_No_midwall_LGE 2819 (92.7%) 418 (76.1%) Ref. Ref.
B_Presence_of_midwall_LGE 223 (7.33%) 131 (23.9%) 3.13 [2.36;4.15] <0.001
CMR_LGE_midwall_extent_count 0.08 (0.28) 0.35 (0.68) 2.44 [2.04;2.90] <0.001 <0.001
CMR_LGE_midwall_extent_categ: 0.000
None 2819 (92.7%) 418 (76.1%) Ref. Ref.
Low_=1 213 (7.00%) 76 (13.8%) 2.22 [1.56;3.15] <0.001
High_>1 10 (0.33%) 55 (10.0%) 7.47 [4.97;11.2] <0.001
CMR_LGE_midwall_location_3: 0.000
No_midwall_LGE 2819 (92.7%) 418 (76.1%) Ref. Ref.
Midwall_LGE_not_at_risk 179 (5.88%) 52 (9.47%) 1.73 [1.14;2.63] <0.001
At_risk_midwall_LGE_(septal_and/or_lateral) 44 (1.45%) 79 (14.4%) 6.41 [4.54;9.06] <0.001
CMR_LGE_midwall_location_4: 0.000
No_midwall_LGE 2819 (92.7%) 418 (76.1%) Ref. Ref.
Midwall_LGE_not_at_risk 179 (5.88%) 52 (9.47%) 1.73 [1.14;2.63] <0.001
Lateral_midwall_LGE 16 (0.53%) 49 (8.93%) 8.41 [5.50;12.9] <0.001
Septal_Midwall_LGE 28 (0.92%) 30 (5.46%) 4.63 [2.72;7.87] <0.001
CMR_LGE_midwall_anterior 82 (2.70%) 17 (3.10%) 1.02 [0.51;2.06] 0.928 0.925
CMR_LGE_midwall_septal 28 (0.92%) 30 (5.46%) 4.03 [2.38;6.84] <0.001 <0.001
CMR_LGE_midwall_inferior 55 (1.81%) 45 (8.20%) 3.93 [2.54;6.08] <0.001 0.000
CMR_LGE_midwall_lateral 16 (0.53%) 54 (9.84%) 7.70 [5.14;11.5] <0.001 0.000
CMR_LGE_midwall_apical 43 (1.41%) 12 (2.19%) 1.29 [0.56;2.98] 0.386 0.366
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab7-univ-LGE-death-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Tab8-multi_tradi-LGE-death

df <- df_LGE %>% mutate(
  event = outcome_death,
  time = outcome_FU_time_death,
  CMR_LVEF_5 = CMR_LVEF/5
) %>% select(
  event, time,
  demo_age, demo_gender, demo_BMI , CV_risk_diabete , CV_risk_Smoking , CV_risk_dyslipidemia ,  history_hospit_HF, history_AFib, med_CKD, history_med_MI , CMR_LVEF_5, CMR_LGE_ischemic_extent_count, CMR_LGE_ischemic_transmurality, CMR_LGE_ischemic_location_4, CMR_LGE_midwall_presence, outcome_revascularisation_90days) %>% droplevels()

#### TABLE 

## Model 1
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LVEF_5))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 1", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 1
Coefficients_CI HR_CI p_value
demo_age 0.03 ( 0.02 - 0.04 ) 1.03 ( 1.02 - 1.04 ) <0.001
demo_genderYes 0.92 ( 0.54 - 1.30 ) 2.51 ( 1.72 - 3.66 ) <0.001
demo_BMI 0.00 ( -0.02 - 0.03 ) 1.00 ( 0.98 - 1.03 ) 0.680
CV_risk_diabeteYes 0.56 ( 0.30 - 0.81 ) 1.74 ( 1.36 - 2.24 ) <0.001
CV_risk_SmokingYes 0.26 ( -0.04 - 0.56 ) 1.30 ( 0.96 - 1.76 ) 0.014
CV_risk_dyslipidemiaYes 0.02 ( -0.23 - 0.26 ) 1.02 ( 0.80 - 1.30 ) 0.855
history_hospit_HFYes 0.54 ( 0.16 - 0.92 ) 1.71 ( 1.17 - 2.50 ) <0.001
history_AFibYes 0.07 ( -0.32 - 0.46 ) 1.07 ( 0.72 - 1.59 ) 0.621
med_CKDYes 0.92 ( 0.37 - 1.47 ) 2.51 ( 1.45 - 4.33 ) <0.001
history_med_MIYes 0.03 ( -0.22 - 0.28 ) 1.03 ( 0.80 - 1.33 ) 0.718
CMR_LVEF_5 -0.09 ( -0.19 - 0.00 ) 0.91 ( 0.83 - 1.00 ) 0.007
## Model 2
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 2", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 2
Coefficients_CI HR_CI p_value
demo_age 0.02 ( 0.01 - 0.03 ) 1.02 ( 1.01 - 1.03 ) <0.001
demo_genderYes 0.74 ( 0.36 - 1.12 ) 2.09 ( 1.43 - 3.05 ) <0.001
demo_BMI 0.01 ( -0.02 - 0.03 ) 1.01 ( 0.98 - 1.03 ) 0.417
CV_risk_diabeteYes 0.37 ( 0.12 - 0.62 ) 1.45 ( 1.13 - 1.86 ) <0.001
CV_risk_SmokingYes 0.25 ( -0.06 - 0.56 ) 1.28 ( 0.94 - 1.74 ) 0.024
CV_risk_dyslipidemiaYes 0.01 ( -0.24 - 0.25 ) 1.01 ( 0.79 - 1.28 ) 0.946
history_hospit_HFYes 0.15 ( -0.24 - 0.54 ) 1.16 ( 0.79 - 1.72 ) 0.276
history_AFibYes -0.03 ( -0.43 - 0.37 ) 0.97 ( 0.65 - 1.44 ) 0.819
med_CKDYes 0.84 ( 0.29 - 1.39 ) 2.32 ( 1.34 - 4.00 ) <0.001
history_med_MIYes -0.03 ( -0.29 - 0.22 ) 0.97 ( 0.75 - 1.25 ) 0.737
CMR_LVEF_5 -0.09 ( -0.18 - 0.01 ) 0.92 ( 0.83 - 1.01 ) 0.013
CMR_LGE_ischemic_extent_count 0.60 ( 0.53 - 0.66 ) 1.82 ( 1.70 - 1.94 ) <0.001
write.csv(data, file = here("outputs", "csv_files","model2_LGE_tradi.csv"), append = FALSE)


## Model 3A
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_transmurality))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 3A", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 3A
Coefficients_CI HR_CI p_value
demo_age 0.01 ( -0.00 - 0.02 ) 1.01 ( 1.00 - 1.02 ) 0.007
demo_genderYes 0.67 ( 0.29 - 1.05 ) 1.95 ( 1.33 - 2.85 ) <0.001
demo_BMI -0.00 ( -0.03 - 0.03 ) 1.00 ( 0.97 - 1.03 ) 0.982
CV_risk_diabeteYes 0.34 ( 0.09 - 0.59 ) 1.40 ( 1.09 - 1.80 ) <0.001
CV_risk_SmokingYes 0.17 ( -0.14 - 0.48 ) 1.19 ( 0.87 - 1.62 ) 0.115
CV_risk_dyslipidemiaYes 0.04 ( -0.20 - 0.29 ) 1.04 ( 0.82 - 1.33 ) 0.644
history_hospit_HFYes 0.02 ( -0.39 - 0.42 ) 1.02 ( 0.68 - 1.53 ) 0.894
history_AFibYes -0.09 ( -0.49 - 0.32 ) 0.92 ( 0.62 - 1.37 ) 0.551
med_CKDYes 0.81 ( 0.26 - 1.36 ) 2.25 ( 1.30 - 3.90 ) <0.001
history_med_MIYes 0.05 ( -0.20 - 0.31 ) 1.06 ( 0.82 - 1.37 ) 0.550
CMR_LVEF_5 -0.06 ( -0.16 - 0.04 ) 0.94 ( 0.85 - 1.04 ) 0.084
CMR_LGE_ischemic_extent_count 0.50 ( 0.44 - 0.57 ) 1.65 ( 1.55 - 1.77 ) <0.001
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 1.04 ( 0.68 - 1.41 ) 2.84 ( 1.97 - 4.09 ) <0.001
CMR_LGE_ischemic_transmuralityD_Transmural 1.67 ( 1.27 - 2.06 ) 5.29 ( 3.55 - 7.88 ) <0.001
## Model 3B
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count, CMR_LGE_ischemic_location_4))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 3B", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 3B
Coefficients_CI HR_CI p_value
demo_age 0.01 ( 0.00 - 0.03 ) 1.01 ( 1.00 - 1.03 ) 0.002
demo_genderYes 0.59 ( 0.21 - 0.98 ) 1.81 ( 1.23 - 2.66 ) <0.001
demo_BMI 0.01 ( -0.02 - 0.03 ) 1.01 ( 0.98 - 1.03 ) 0.569
CV_risk_diabeteYes 0.32 ( 0.07 - 0.57 ) 1.38 ( 1.07 - 1.77 ) <0.001
CV_risk_SmokingYes 0.14 ( -0.17 - 0.45 ) 1.15 ( 0.85 - 1.57 ) 0.201
CV_risk_dyslipidemiaYes 0.02 ( -0.23 - 0.26 ) 1.02 ( 0.80 - 1.30 ) 0.857
history_hospit_HFYes -0.00 ( -0.40 - 0.40 ) 1.00 ( 0.67 - 1.49 ) 0.994
history_AFibYes -0.28 ( -0.68 - 0.13 ) 0.76 ( 0.51 - 1.13 ) 0.053
med_CKDYes 0.69 ( 0.14 - 1.25 ) 2.00 ( 1.15 - 3.48 ) <0.001
history_med_MIYes -0.06 ( -0.32 - 0.19 ) 0.94 ( 0.73 - 1.21 ) 0.491
CMR_LVEF_5 -0.05 ( -0.14 - 0.05 ) 0.96 ( 0.87 - 1.06 ) 0.205
CMR_LGE_ischemic_extent_count 0.36 ( 0.29 - 0.43 ) 1.44 ( 1.33 - 1.54 ) <0.001
CMR_LGE_ischemic_location_4C_Anterior_without_septal 1.67 ( 1.27 - 2.07 ) 5.33 ( 3.57 - 7.96 ) <0.001
CMR_LGE_ischemic_location_4D_Septal 2.20 ( 1.83 - 2.56 ) 9.00 ( 6.26 - 12.94 ) <0.001
## Model 3C
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count, CMR_LGE_midwall_presence))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 3C", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 3C
Coefficients_CI HR_CI p_value
demo_age 0.02 ( 0.00 - 0.03 ) 1.02 ( 1.00 - 1.03 ) <0.001
demo_genderYes 0.77 ( 0.39 - 1.15 ) 2.15 ( 1.47 - 3.14 ) <0.001
demo_BMI 0.00 ( -0.02 - 0.03 ) 1.00 ( 0.98 - 1.03 ) 0.670
CV_risk_diabeteYes 0.38 ( 0.13 - 0.63 ) 1.46 ( 1.14 - 1.88 ) <0.001
CV_risk_SmokingYes 0.28 ( -0.03 - 0.59 ) 1.32 ( 0.97 - 1.80 ) 0.011
CV_risk_dyslipidemiaYes 0.04 ( -0.21 - 0.28 ) 1.04 ( 0.81 - 1.33 ) 0.661
history_hospit_HFYes 0.20 ( -0.19 - 0.59 ) 1.22 ( 0.83 - 1.81 ) 0.149
history_AFibYes -0.00 ( -0.40 - 0.40 ) 1.00 ( 0.67 - 1.49 ) 0.995
med_CKDYes 0.85 ( 0.31 - 1.40 ) 2.35 ( 1.36 - 4.05 ) <0.001
history_med_MIYes -0.04 ( -0.30 - 0.22 ) 0.96 ( 0.74 - 1.24 ) 0.663
CMR_LVEF_5 -0.07 ( -0.17 - 0.03 ) 0.93 ( 0.84 - 1.03 ) 0.048
CMR_LGE_ischemic_extent_count 0.57 ( 0.51 - 0.64 ) 1.78 ( 1.66 - 1.89 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.68 ( 0.39 - 0.98 ) 1.98 ( 1.48 - 2.66 ) <0.001
## Model 4
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event: CMR_LGE_midwall_presence))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 4", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 4
Coefficients_CI HR_CI p_value
demo_age 0.01 ( -0.00 - 0.02 ) 1.01 ( 1.00 - 1.02 ) 0.052
demo_genderYes 0.56 ( 0.17 - 0.94 ) 1.75 ( 1.19 - 2.57 ) <0.001
demo_BMI 0.00 ( -0.03 - 0.03 ) 1.00 ( 0.97 - 1.03 ) 0.961
CV_risk_diabeteYes 0.30 ( 0.05 - 0.55 ) 1.35 ( 1.05 - 1.73 ) <0.001
CV_risk_SmokingYes 0.12 ( -0.19 - 0.43 ) 1.13 ( 0.83 - 1.54 ) 0.283
CV_risk_dyslipidemiaYes 0.09 ( -0.16 - 0.34 ) 1.10 ( 0.86 - 1.40 ) 0.297
history_hospit_HFYes -0.01 ( -0.42 - 0.40 ) 0.99 ( 0.66 - 1.48 ) 0.942
history_AFibYes -0.24 ( -0.64 - 0.16 ) 0.78 ( 0.53 - 1.17 ) 0.090
med_CKDYes 0.71 ( 0.16 - 1.26 ) 2.04 ( 1.17 - 3.54 ) <0.001
history_med_MIYes -0.02 ( -0.28 - 0.24 ) 0.98 ( 0.76 - 1.27 ) 0.833
CMR_LVEF_5 -0.01 ( -0.11 - 0.09 ) 0.99 ( 0.89 - 1.09 ) 0.738
CMR_LGE_ischemic_extent_count 0.32 ( 0.24 - 0.39 ) 1.37 ( 1.28 - 1.48 ) <0.001
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 0.79 ( 0.42 - 1.16 ) 2.21 ( 1.53 - 3.20 ) <0.001
CMR_LGE_ischemic_transmuralityD_Transmural 1.07 ( 0.67 - 1.48 ) 2.92 ( 1.94 - 4.39 ) <0.001
CMR_LGE_ischemic_location_4C_Anterior_without_septal 1.60 ( 1.20 - 2.01 ) 4.96 ( 3.31 - 7.44 ) <0.001
CMR_LGE_ischemic_location_4D_Septal 1.97 ( 1.59 - 2.34 ) 7.14 ( 4.92 - 10.36 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.62 ( 0.33 - 0.91 ) 1.86 ( 1.39 - 2.50 ) <0.001
write.csv(data, file = here("outputs", "csv_files","model4_LGE_tradi.csv"), append = FALSE)

## Model 5
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event: outcome_revascularisation_90days))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 4", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 4
Coefficients_CI HR_CI p_value
demo_age 0.01 ( -0.01 - 0.02 ) 1.01 ( 0.99 - 1.02 ) 0.171
demo_genderYes 0.55 ( 0.17 - 0.94 ) 1.74 ( 1.18 - 2.56 ) <0.001
demo_BMI 0.00 ( -0.03 - 0.03 ) 1.00 ( 0.97 - 1.03 ) 0.927
CV_risk_diabeteYes 0.30 ( 0.05 - 0.55 ) 1.35 ( 1.05 - 1.73 ) <0.001
CV_risk_SmokingYes 0.11 ( -0.20 - 0.42 ) 1.12 ( 0.82 - 1.53 ) 0.316
CV_risk_dyslipidemiaYes 0.08 ( -0.17 - 0.33 ) 1.09 ( 0.85 - 1.39 ) 0.349
history_hospit_HFYes -0.02 ( -0.42 - 0.39 ) 0.98 ( 0.66 - 1.48 ) 0.910
history_AFibYes -0.23 ( -0.63 - 0.17 ) 0.79 ( 0.53 - 1.19 ) 0.107
med_CKDYes 0.71 ( 0.16 - 1.26 ) 2.03 ( 1.17 - 3.52 ) <0.001
history_med_MIYes -0.03 ( -0.29 - 0.23 ) 0.97 ( 0.75 - 1.26 ) 0.740
CMR_LVEF_5 -0.01 ( -0.11 - 0.09 ) 0.99 ( 0.89 - 1.09 ) 0.751
CMR_LGE_ischemic_extent_count 0.32 ( 0.24 - 0.39 ) 1.37 ( 1.27 - 1.48 ) <0.001
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 0.78 ( 0.42 - 1.15 ) 2.19 ( 1.52 - 3.17 ) <0.001
CMR_LGE_ischemic_transmuralityD_Transmural 0.91 ( 0.43 - 1.38 ) 2.47 ( 1.54 - 3.96 ) <0.001
CMR_LGE_ischemic_location_4C_Anterior_without_septal 1.60 ( 1.19 - 2.00 ) 4.94 ( 3.30 - 7.40 ) <0.001
CMR_LGE_ischemic_location_4D_Septal 1.95 ( 1.58 - 2.33 ) 7.05 ( 4.85 - 10.23 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.62 ( 0.32 - 0.91 ) 1.85 ( 1.38 - 2.49 ) <0.001
outcome_revascularisation_90daysYes -0.24 ( -0.59 - 0.11 ) 0.79 ( 0.55 - 1.11 ) 0.053
write.csv(data, file = here("outputs", "csv_files","model5_LGE_tradi.csv"), append = FALSE)

## MODELS MULTI NESTED
var_base = c("demo_age", "demo_gender" , "demo_BMI" , "CV_risk_diabete" , "CV_risk_Smoking" , "CV_risk_dyslipidemia" ,  "history_hospit_HF", "history_AFib" , "med_CKD" , "history_med_MI" , "CMR_LVEF_5")

### Nested 4
table <- uni_multi_function(
  df = df, 
  event = "event",
  time = "time", 
  var_base = var_base, 
  var_added = c("CMR_LGE_ischemic_extent_count", "CMR_LGE_ischemic_transmurality","CMR_LGE_ischemic_location_4",
                "CMR_LGE_midwall_presence", "outcome_revascularisation_90days"))

# export in html
knitr::kable(table, caption = "Model full - granularity until revasc (LGE pop = 3,591)", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model full - granularity until revasc (LGE pop = 3,591)
Variable Univariate_Analysis model_multi_1 model_multi_2 model_multi_3 model_multi_4 model_multi_5 model_multi_6
demo_age 1.03 (1.02-1.04), p=0.000 1.03 (1.02-1.04), p=0.000 1.02 (1.01-1.03), p=0.000 1.01 (1.00-1.02), p=0.007 1.01 (1.00-1.02), p=0.017 1.01 (1.00-1.02), p=0.052 1.01 (0.99-1.02), p=0.171
demo_genderYes 2.64 (1.82-3.84), p=0.000 2.51 (1.72-3.66), p=0.000 2.09 (1.43-3.05), p=0.000 1.95 (1.33-2.85), p=0.000 1.75 (1.19-2.58), p=0.000 1.75 (1.19-2.57), p=0.000 1.74 (1.18-2.56), p=0.000
demo_BMI 1.00 (0.98-1.03), p=0.600 1.00 (0.98-1.03), p=0.680 1.01 (0.98-1.03), p=0.417 1.00 (0.97-1.03), p=0.982 1.00 (0.98-1.03), p=0.761 1.00 (0.97-1.03), p=0.961 1.00 (0.97-1.03), p=0.927
CV_risk_diabeteYes 1.96 (1.54-2.50), p=0.000 1.74 (1.36-2.24), p=0.000 1.45 (1.13-1.86), p=0.000 1.40 (1.09-1.80), p=0.000 1.36 (1.06-1.76), p=0.001 1.35 (1.05-1.73), p=0.001 1.35 (1.05-1.73), p=0.001
CV_risk_SmokingYes 1.10 (0.83-1.47), p=0.328 1.30 (0.96-1.76), p=0.014 1.28 (0.94-1.74), p=0.024 1.19 (0.87-1.62), p=0.115 1.10 (0.81-1.50), p=0.374 1.13 (0.83-1.54), p=0.283 1.12 (0.82-1.53), p=0.316
CV_risk_dyslipidemiaYes 1.11 (0.87-1.41), p=0.224 1.02 (0.80-1.30), p=0.855 1.01 (0.79-1.28), p=0.946 1.04 (0.82-1.33), p=0.644 1.03 (0.80-1.31), p=0.760 1.10 (0.86-1.40), p=0.297 1.09 (0.85-1.39), p=0.349
history_hospit_HFYes 2.39 (1.68-3.41), p=0.000 1.71 (1.17-2.50), p=0.000 1.16 (0.79-1.72), p=0.276 1.02 (0.68-1.53), p=0.894 0.92 (0.61-1.38), p=0.563 0.99 (0.66-1.48), p=0.942 0.98 (0.66-1.48), p=0.910
history_AFibYes 1.61 (1.10-2.36), p=0.000 1.07 (0.72-1.59), p=0.621 0.97 (0.65-1.44), p=0.819 0.92 (0.62-1.37), p=0.551 0.75 (0.50-1.12), p=0.047 0.78 (0.53-1.17), p=0.090 0.79 (0.53-1.19), p=0.107
med_CKDYes 3.69 (2.18-6.26), p=0.000 2.51 (1.45-4.33), p=0.000 2.32 (1.34-4.00), p=0.000 2.25 (1.30-3.90), p=0.000 1.97 (1.13-3.43), p=0.001 2.04 (1.17-3.54), p=0.000 2.03 (1.17-3.52), p=0.000
history_med_MIYes 1.07 (0.83-1.36), p=0.463 1.03 (0.80-1.33), p=0.718 0.97 (0.75-1.25), p=0.737 1.06 (0.82-1.37), p=0.550 1.01 (0.78-1.30), p=0.929 0.98 (0.76-1.27), p=0.833 0.97 (0.75-1.26), p=0.740
CMR_LVEF_5 0.82 (0.75-0.89), p=0.000 0.91 (0.83-1.00), p=0.007 0.92 (0.83-1.01), p=0.013 0.94 (0.85-1.04), p=0.084 0.97 (0.87-1.07), p=0.357 0.99 (0.89-1.09), p=0.738 0.99 (0.89-1.09), p=0.751
CMR_LGE_ischemic_extent_count 1.90 (1.78-2.02), p=0.000 NA 1.82 (1.70-1.94), p=0.000 1.65 (1.55-1.77), p=0.000 1.38 (1.28-1.49), p=0.000 1.37 (1.28-1.48), p=0.000 1.37 (1.27-1.48), p=0.000
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 3.57 (2.49-5.12), p=0.000 NA NA 2.84 (1.97-4.09), p=0.000 2.26 (1.56-3.27), p=0.000 2.21 (1.53-3.20), p=0.000 2.19 (1.52-3.17), p=0.000
CMR_LGE_ischemic_transmuralityD_Transmural 14.73 (10.17-21.34), p=0.000 NA NA 5.29 (3.55-7.88), p=0.000 3.14 (2.09-4.73), p=0.000 2.92 (1.94-4.39), p=0.000 2.47 (1.54-3.96), p=0.000
CMR_LGE_ischemic_location_4C_Anterior_without_septal 7.22 (4.87-10.70), p=0.000 NA NA NA 5.05 (3.38-7.55), p=0.000 4.96 (3.31-7.44), p=0.000 4.94 (3.30-7.40), p=0.000
CMR_LGE_ischemic_location_4D_Septal 21.91 (15.90-30.18), p=0.000 NA NA NA 7.09 (4.87-10.32), p=0.000 7.14 (4.92-10.36), p=0.000 7.05 (4.85-10.23), p=0.000
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 3.13 (2.36-4.15), p=0.000 NA NA NA NA 1.86 (1.39-2.50), p=0.000 1.85 (1.38-2.49), p=0.000
outcome_revascularisation_90daysYes 0.23 (0.18-0.29), p=0.000 NA NA NA NA NA 0.79 (0.55-1.11), p=0.053
# Export in word
ft <- flextable(table)
ft <- set_table_properties(ft, layout = "autofit")
doc <- read_docx() %>%
  body_add_par("Model 4 - LGE pop (N=3,591)", style = "heading 1") %>%
  body_add_flextable(ft)
print(doc, target = here(tables_output_dir,paste0("Tab8-multi_tradi-LGE-death-",Sys.Date(), ".docx")))

Tab9-multi_stepwise-LGE-death OK

library(dplyr)
library(StepReg)
library(survival)

# Assuming df_LGE is your initial dataset
df_selected <- df_all %>% 
  mutate_if(is.factor, as.numeric) %>% mutate(
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVESV_10 = CMR_LVESV/10,
    CMR_LVEDV_10 = CMR_LVEDV/10
  ) %>%
  select(outcome_death, outcome_FU_time_death,
         demo_age, demo_gender, demo_BMI, CV_risk_diabete, CV_risk_obesity, CV_risk_dyslipidemia,
         CV_risk_Smoking, history_med_MI, history_coronary_procedure, history_interv_PCI, history_interv_CABG, med_periph_atheroma, history_stroke, med_pacemaker, med_CKD, history_hospit_HF, history_AFib, clini_NYHA,
         clini_cardiac_rythm, CMR_LVEF_5, CMR_LVESV_10, CMR_LVEDV_10,
         CMR_LV_mass, CMR_RV_dysfunction) # CV_risk_HTA

# Define the Cox model formula
formula <- Surv(outcome_FU_time_death, outcome_death) ~ .

# Run stepwise Cox regression
stepwise_result <- stepwiseCox(
  formula = formula,
  data = df_selected,
  sle = 0.1,
  sls = 0.1,
  selection = "forward",  # Choose your selection method
  select = "SL" #,              # Choose your selection criterion
  # method = "Breslow"            # Choose your method for tie handling "Efron"
)

# View the results
summary(stepwise_result)
##                                        Length Class      Mode
## Summary of Parameters                   2     data.frame list
## Variables Type                          2     data.frame list
## Process of Selection                    6     data.frame list
## Selected Varaibles                     11     data.frame list
## Coefficients of the Selected Variables  6     data.frame list
var_select <- as.data.frame(t(stepwise_result$`Selected Varaibles`[1,]))$xModel
var_select
##  [1] "demo_gender"         "demo_age"            "CV_risk_diabete"    
##  [4] "CMR_RV_dysfunction"  "med_CKD"             "history_hospit_HF"  
##  [7] "CMR_LVEF_5"          "history_stroke"      "med_periph_atheroma"
## [10] "med_pacemaker"       "CV_risk_Smoking"
#### Multivariable analysis
# taking the LGE variables into account 
df <- df_LGE %>% mutate(
  event = outcome_death,
  time = outcome_FU_time_death,
  CMR_LVEF_5 = CMR_LVEF/5
) %>% select(
  event, time,
  var_select, CMR_LGE_ischemic_extent_count, CMR_LGE_ischemic_transmurality, CMR_LGE_ischemic_location_4, CMR_LGE_midwall_presence, outcome_revascularisation_90days) %>% droplevels()

#### TABLE 

## Model 1
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CV_risk_Smoking))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model stepwise 1", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model stepwise 1
Coefficients_CI HR_CI p_value
demo_genderYes 0.90 ( 0.52 - 1.28 ) 2.45 ( 1.68 - 3.58 ) <0.001
demo_age 0.03 ( 0.02 - 0.04 ) 1.03 ( 1.02 - 1.04 ) <0.001
CV_risk_diabeteYes 0.56 ( 0.32 - 0.81 ) 1.76 ( 1.38 - 2.24 ) <0.001
CMR_RV_dysfunctionYes 0.84 ( 0.44 - 1.25 ) 2.33 ( 1.55 - 3.48 ) <0.001
med_CKDYes 0.92 ( 0.38 - 1.47 ) 2.52 ( 1.46 - 4.35 ) <0.001
history_hospit_HFYes 0.47 ( 0.09 - 0.85 ) 1.60 ( 1.09 - 2.34 ) <0.001
CMR_LVEF_5 -0.07 ( -0.17 - 0.02 ) 0.93 ( 0.85 - 1.02 ) 0.029
history_strokeYes 0.55 ( 0.03 - 1.06 ) 1.73 ( 1.03 - 2.89 ) 0.003
med_periph_atheromaYes 0.34 ( -0.06 - 0.74 ) 1.41 ( 0.94 - 2.09 ) 0.016
med_pacemakerYes -0.86 ( -2.49 - 0.78 ) 0.43 ( 0.08 - 2.19 ) 0.142
CV_risk_SmokingYes 0.21 ( -0.09 - 0.51 ) 1.23 ( 0.91 - 1.66 ) 0.049
write.csv(data, file = here("outputs", "csv_files","model1_stepwise.csv"), append = FALSE)

## Model 2
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model stepwise 2", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model stepwise 2
Coefficients_CI HR_CI p_value
demo_genderYes 0.72 ( 0.34 - 1.10 ) 2.05 ( 1.40 - 2.99 ) <0.001
demo_age 0.02 ( 0.00 - 0.03 ) 1.02 ( 1.00 - 1.03 ) <0.001
CV_risk_diabeteYes 0.38 ( 0.13 - 0.62 ) 1.46 ( 1.14 - 1.86 ) <0.001
CMR_RV_dysfunctionYes 0.31 ( -0.10 - 0.72 ) 1.36 ( 0.90 - 2.05 ) 0.036
med_CKDYes 0.89 ( 0.36 - 1.43 ) 2.45 ( 1.43 - 4.20 ) <0.001
history_hospit_HFYes 0.11 ( -0.28 - 0.51 ) 1.12 ( 0.75 - 1.66 ) 0.427
CMR_LVEF_5 -0.08 ( -0.17 - 0.02 ) 0.93 ( 0.84 - 1.02 ) 0.022
history_strokeYes 0.61 ( 0.09 - 1.12 ) 1.83 ( 1.09 - 3.07 ) <0.001
med_periph_atheromaYes 0.22 ( -0.17 - 0.62 ) 1.25 ( 0.84 - 1.86 ) 0.115
med_pacemakerYes -0.78 ( -2.41 - 0.86 ) 0.46 ( 0.09 - 2.36 ) 0.182
CV_risk_SmokingYes 0.21 ( -0.09 - 0.52 ) 1.24 ( 0.91 - 1.68 ) 0.052
CMR_LGE_ischemic_extent_count 0.59 ( 0.52 - 0.65 ) 1.80 ( 1.69 - 1.92 ) <0.001
## Model 3A
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_transmurality))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model stepwise 3A", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model stepwise 3A
Coefficients_CI HR_CI p_value
demo_genderYes 0.67 ( 0.29 - 1.05 ) 1.95 ( 1.33 - 2.85 ) <0.001
demo_age 0.01 ( -0.00 - 0.02 ) 1.01 ( 1.00 - 1.02 ) 0.007
CV_risk_diabeteYes 0.33 ( 0.09 - 0.58 ) 1.40 ( 1.09 - 1.79 ) <0.001
CMR_RV_dysfunctionYes 0.11 ( -0.31 - 0.52 ) 1.11 ( 0.73 - 1.69 ) 0.470
med_CKDYes 0.81 ( 0.26 - 1.35 ) 2.24 ( 1.30 - 3.86 ) <0.001
history_hospit_HFYes -0.01 ( -0.42 - 0.39 ) 0.99 ( 0.66 - 1.48 ) 0.929
CMR_LVEF_5 -0.07 ( -0.16 - 0.03 ) 0.94 ( 0.85 - 1.03 ) 0.057
history_strokeYes 0.55 ( 0.04 - 1.07 ) 1.74 ( 1.04 - 2.90 ) 0.003
med_periph_atheromaYes 0.10 ( -0.30 - 0.50 ) 1.11 ( 0.74 - 1.65 ) 0.478
med_pacemakerYes -0.81 ( -2.44 - 0.83 ) 0.45 ( 0.09 - 2.30 ) 0.167
CV_risk_SmokingYes 0.16 ( -0.14 - 0.47 ) 1.18 ( 0.87 - 1.60 ) 0.131
CMR_LGE_ischemic_extent_count 0.50 ( 0.43 - 0.57 ) 1.65 ( 1.54 - 1.77 ) <0.001
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 1.02 ( 0.66 - 1.39 ) 2.79 ( 1.94 - 4.01 ) <0.001
CMR_LGE_ischemic_transmuralityD_Transmural 1.64 ( 1.24 - 2.04 ) 5.15 ( 3.45 - 7.68 ) <0.001
## Model 3B
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count, CMR_LGE_ischemic_location_4))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model stepwise 3B", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model stepwise 3B
Coefficients_CI HR_CI p_value
demo_genderYes 0.59 ( 0.20 - 0.97 ) 1.80 ( 1.23 - 2.65 ) <0.001
demo_age 0.01 ( -0.00 - 0.02 ) 1.01 ( 1.00 - 1.02 ) 0.007
CV_risk_diabeteYes 0.31 ( 0.07 - 0.56 ) 1.37 ( 1.07 - 1.75 ) <0.001
CMR_RV_dysfunctionYes 0.11 ( -0.30 - 0.52 ) 1.12 ( 0.74 - 1.68 ) 0.438
med_CKDYes 0.67 ( 0.13 - 1.22 ) 1.96 ( 1.14 - 3.38 ) <0.001
history_hospit_HFYes 0.00 ( -0.39 - 0.40 ) 1.00 ( 0.68 - 1.49 ) 0.991
CMR_LVEF_5 -0.03 ( -0.13 - 0.06 ) 0.97 ( 0.88 - 1.07 ) 0.334
history_strokeYes 0.68 ( 0.16 - 1.20 ) 1.97 ( 1.17 - 3.31 ) <0.001
med_periph_atheromaYes 0.06 ( -0.33 - 0.46 ) 1.07 ( 0.72 - 1.58 ) 0.656
med_pacemakerYes 0.35 ( -1.30 - 2.00 ) 1.42 ( 0.27 - 7.40 ) 0.549
CV_risk_SmokingYes 0.13 ( -0.18 - 0.43 ) 1.14 ( 0.84 - 1.54 ) 0.245
CMR_LGE_ischemic_extent_count 0.36 ( 0.28 - 0.43 ) 1.43 ( 1.33 - 1.54 ) <0.001
CMR_LGE_ischemic_location_4C_Anterior_without_septal 1.65 ( 1.25 - 2.06 ) 5.23 ( 3.50 - 7.82 ) <0.001
CMR_LGE_ischemic_location_4D_Septal 2.19 ( 1.83 - 2.56 ) 8.97 ( 6.22 - 12.93 ) <0.001
## Model 3C
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count, CMR_LGE_midwall_presence))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model stepwise 3C", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model stepwise 3C
Coefficients_CI HR_CI p_value
demo_genderYes 0.75 ( 0.37 - 1.13 ) 2.13 ( 1.45 - 3.11 ) <0.001
demo_age 0.02 ( 0.00 - 0.03 ) 1.02 ( 1.00 - 1.03 ) <0.001
CV_risk_diabeteYes 0.38 ( 0.14 - 0.63 ) 1.47 ( 1.15 - 1.88 ) <0.001
CMR_RV_dysfunctionYes 0.26 ( -0.16 - 0.67 ) 1.29 ( 0.85 - 1.96 ) 0.081
med_CKDYes 0.90 ( 0.37 - 1.44 ) 2.47 ( 1.44 - 4.23 ) <0.001
history_hospit_HFYes 0.17 ( -0.23 - 0.56 ) 1.18 ( 0.79 - 1.76 ) 0.238
CMR_LVEF_5 -0.06 ( -0.16 - 0.03 ) 0.94 ( 0.85 - 1.04 ) 0.073
history_strokeYes 0.62 ( 0.11 - 1.14 ) 1.86 ( 1.11 - 3.12 ) <0.001
med_periph_atheromaYes 0.20 ( -0.20 - 0.60 ) 1.22 ( 0.82 - 1.82 ) 0.162
med_pacemakerYes -0.81 ( -2.44 - 0.83 ) 0.45 ( 0.09 - 2.30 ) 0.167
CV_risk_SmokingYes 0.25 ( -0.06 - 0.55 ) 1.28 ( 0.94 - 1.74 ) 0.023
CMR_LGE_ischemic_extent_count 0.57 ( 0.50 - 0.63 ) 1.76 ( 1.65 - 1.88 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.68 ( 0.39 - 0.97 ) 1.97 ( 1.47 - 2.64 ) <0.001
## Model 4
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event: CMR_LGE_midwall_presence))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model stepwise 4", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model stepwise 4
Coefficients_CI HR_CI p_value
demo_genderYes 0.57 ( 0.18 - 0.96 ) 1.77 ( 1.20 - 2.60 ) <0.001
demo_age 0.01 ( -0.00 - 0.02 ) 1.01 ( 1.00 - 1.02 ) 0.088
CV_risk_diabeteYes 0.29 ( 0.05 - 0.54 ) 1.34 ( 1.05 - 1.71 ) <0.001
CMR_RV_dysfunctionYes -0.06 ( -0.47 - 0.35 ) 0.94 ( 0.62 - 1.42 ) 0.683
med_CKDYes 0.69 ( 0.14 - 1.23 ) 1.98 ( 1.15 - 3.41 ) <0.001
history_hospit_HFYes -0.00 ( -0.41 - 0.40 ) 1.00 ( 0.67 - 1.49 ) 0.978
CMR_LVEF_5 -0.01 ( -0.11 - 0.09 ) 0.99 ( 0.90 - 1.09 ) 0.781
history_strokeYes 0.69 ( 0.17 - 1.21 ) 2.00 ( 1.19 - 3.36 ) <0.001
med_periph_atheromaYes -0.02 ( -0.42 - 0.38 ) 0.98 ( 0.66 - 1.46 ) 0.897
med_pacemakerYes 0.33 ( -1.32 - 1.97 ) 1.38 ( 0.27 - 7.18 ) 0.579
CV_risk_SmokingYes 0.12 ( -0.18 - 0.43 ) 1.13 ( 0.83 - 1.54 ) 0.260
CMR_LGE_ischemic_extent_count 0.31 ( 0.24 - 0.39 ) 1.37 ( 1.27 - 1.48 ) <0.001
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 0.77 ( 0.40 - 1.14 ) 2.16 ( 1.49 - 3.13 ) <0.001
CMR_LGE_ischemic_transmuralityD_Transmural 1.07 ( 0.66 - 1.47 ) 2.90 ( 1.93 - 4.36 ) <0.001
CMR_LGE_ischemic_location_4C_Anterior_without_septal 1.59 ( 1.19 - 2.00 ) 4.92 ( 3.28 - 7.37 ) <0.001
CMR_LGE_ischemic_location_4D_Septal 1.98 ( 1.60 - 2.35 ) 7.21 ( 4.96 - 10.49 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.64 ( 0.35 - 0.93 ) 1.89 ( 1.41 - 2.53 ) <0.001
write.csv(data, file = here("outputs", "csv_files","model4_stepwise.csv"), append = FALSE)

## model uni - multi
table <- uni_multi_function(
  df = df, 
  event = "event",
  time = "time", 
  var_base = var_select, 
  var_added = c("CMR_LGE_ischemic_extent_count", "CMR_LGE_ischemic_transmurality","CMR_LGE_ischemic_location_4",
                "CMR_LGE_midwall_presence", "outcome_revascularisation_90days"))

# export in html
knitr::kable(table, caption = "Model 4 - granularity + revasc (LGE pop = 3,591)", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 4 - granularity + revasc (LGE pop = 3,591)
Variable Univariate_Analysis model_multi_1 model_multi_2 model_multi_3 model_multi_4 model_multi_5 model_multi_6
demo_genderYes 2.64 (1.82-3.84), p=0.000 2.45 (1.68-3.58), p=0.000 2.05 (1.40-2.99), p=0.000 1.95 (1.33-2.85), p=0.000 1.75 (1.19-2.58), p=0.000 1.77 (1.20-2.60), p=0.000 1.76 (1.20-2.59), p=0.000
demo_age 1.03 (1.02-1.04), p=0.000 1.03 (1.02-1.04), p=0.000 1.02 (1.00-1.03), p=0.000 1.01 (1.00-1.02), p=0.007 1.01 (1.00-1.02), p=0.053 1.01 (1.00-1.02), p=0.088 1.00 (0.99-1.02), p=0.262
CV_risk_diabeteYes 1.96 (1.54-2.50), p=0.000 1.76 (1.38-2.24), p=0.000 1.46 (1.14-1.86), p=0.000 1.40 (1.09-1.79), p=0.000 1.35 (1.06-1.73), p=0.001 1.34 (1.05-1.71), p=0.001 1.34 (1.05-1.71), p=0.001
CMR_RV_dysfunctionYes 3.15 (2.13-4.65), p=0.000 2.33 (1.55-3.48), p=0.000 1.36 (0.90-2.05), p=0.036 1.11 (0.73-1.69), p=0.470 1.01 (0.67-1.52), p=0.948 0.94 (0.62-1.42), p=0.683 0.94 (0.62-1.42), p=0.685
med_CKDYes 3.69 (2.18-6.26), p=0.000 2.52 (1.46-4.35), p=0.000 2.45 (1.43-4.20), p=0.000 2.24 (1.30-3.86), p=0.000 1.93 (1.12-3.32), p=0.001 1.98 (1.15-3.41), p=0.000 1.99 (1.16-3.42), p=0.000
history_hospit_HFYes 2.39 (1.68-3.41), p=0.000 1.60 (1.09-2.34), p=0.001 1.12 (0.75-1.66), p=0.427 0.99 (0.66-1.48), p=0.929 0.93 (0.62-1.39), p=0.603 1.00 (0.67-1.49), p=0.978 0.99 (0.66-1.48), p=0.953
CMR_LVEF_5 0.82 (0.75-0.89), p=0.000 0.93 (0.85-1.02), p=0.029 0.93 (0.84-1.02), p=0.022 0.94 (0.85-1.03), p=0.057 0.97 (0.88-1.07), p=0.385 0.99 (0.90-1.09), p=0.781 0.99 (0.90-1.10), p=0.821
history_strokeYes 1.99 (1.20-3.33), p=0.000 1.73 (1.03-2.89), p=0.003 1.83 (1.09-3.07), p=0.001 1.74 (1.04-2.90), p=0.003 1.88 (1.12-3.16), p=0.001 2.00 (1.19-3.36), p=0.000 1.97 (1.17-3.32), p=0.000
med_periph_atheromaYes 1.99 (1.35-2.94), p=0.000 1.41 (0.94-2.09), p=0.016 1.25 (0.84-1.86), p=0.115 1.11 (0.74-1.65), p=0.478 1.01 (0.68-1.51), p=0.940 0.98 (0.66-1.46), p=0.897 0.98 (0.65-1.46), p=0.864
med_pacemakerYes 0.83 (0.16-4.20), p=0.741 0.43 (0.08-2.19), p=0.142 0.46 (0.09-2.36), p=0.182 0.45 (0.09-2.30), p=0.167 1.34 (0.26-6.93), p=0.622 1.38 (0.27-7.18), p=0.579 1.34 (0.26-6.97), p=0.615
CV_risk_SmokingYes 1.10 (0.83-1.47), p=0.328 1.23 (0.91-1.66), p=0.049 1.24 (0.91-1.68), p=0.052 1.18 (0.87-1.60), p=0.131 1.10 (0.81-1.49), p=0.391 1.13 (0.83-1.54), p=0.260 1.12 (0.82-1.53), p=0.291
CMR_LGE_ischemic_extent_count 1.90 (1.78-2.02), p=0.000 NA 1.80 (1.69-1.92), p=0.000 1.65 (1.54-1.77), p=0.000 1.38 (1.28-1.48), p=0.000 1.37 (1.27-1.48), p=0.000 1.37 (1.27-1.47), p=0.000
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 3.57 (2.49-5.12), p=0.000 NA NA 2.79 (1.94-4.01), p=0.000 2.22 (1.53-3.21), p=0.000 2.16 (1.49-3.13), p=0.000 2.15 (1.48-3.11), p=0.000
CMR_LGE_ischemic_transmuralityD_Transmural 14.73 (10.17-21.34), p=0.000 NA NA 5.15 (3.45-7.68), p=0.000 3.10 (2.06-4.66), p=0.000 2.90 (1.93-4.36), p=0.000 2.47 (1.55-3.94), p=0.000
CMR_LGE_ischemic_location_4C_Anterior_without_septal 7.22 (4.87-10.70), p=0.000 NA NA NA 4.96 (3.31-7.43), p=0.000 4.92 (3.28-7.37), p=0.000 4.90 (3.27-7.34), p=0.000
CMR_LGE_ischemic_location_4D_Septal 21.91 (15.90-30.18), p=0.000 NA NA NA 7.13 (4.89-10.40), p=0.000 7.21 (4.96-10.49), p=0.000 7.12 (4.89-10.35), p=0.000
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 3.13 (2.36-4.15), p=0.000 NA NA NA NA 1.89 (1.41-2.53), p=0.000 1.89 (1.41-2.53), p=0.000
outcome_revascularisation_90daysYes 0.23 (0.18-0.29), p=0.000 NA NA NA NA NA 0.79 (0.55-1.11), p=0.053
# Export in word
ft <- flextable(table)
ft <- set_table_properties(ft, layout = "autofit")
doc <- read_docx() %>%
  body_add_par("Model full - LGE pop (N=3,591)", style = "heading 1") %>%
  body_add_flextable(ft)

print(doc, target = here(tables_output_dir,paste0("Tab9-multi_stepwise-LGE-death-",Sys.Date(), ".docx")))

Tab10-incr_tradi-LGE-death

var1 <- c("demo_age", "demo_gender" , "demo_BMI" , "CV_risk_diabete" , "CV_risk_Smoking" , "CV_risk_dyslipidemia" ,  "history_hospit_HF", "history_AFib" , "med_CKD" , "history_med_MI" , "CMR_LVEF_5")
var2 <- c(var1, "CMR_LGE_ischemic_extent_count")
var3A <- c(var2, "CMR_LGE_ischemic_transmurality")
var3B <- c(var2, "CMR_LGE_ischemic_location_4")
var3C <-  c(var2, "CMR_LGE_midwall_presence")
var4 <- c(var2, "CMR_LGE_ischemic_transmurality", "CMR_LGE_ischemic_location_4", "CMR_LGE_midwall_presence")

df_LGE <- df_LGE %>% mutate(
  time = outcome_FU_time_death,
  event = outcome_death,
  CMR_LVEF_5 = CMR_LVEF/5
)%>% droplevels()

# MODEL 1
results.model1 <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var1, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model1$model_stats
## NULL
results.model1$derivation$auc
## [1] "0.69 [0.65-0.72]"
# MODEL 2
results.model2 <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var2, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model2$model_stats
## NULL
results.model2$derivation$auc
## [1] "0.84 [0.81-0.86]"
roc.test(results.model1$roc_derivation$roc_obj, results.model2$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model1$roc_derivation$roc_obj and results.model2$roc_derivation$roc_obj
## Z = -10.482, p-value < 2.2e-16
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.1788057 -0.1224720
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.6854679   0.8361068
# MODEL 3A
results.model3A <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3A, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3A$model_stats
## NULL
results.model3A$derivation$auc
## [1] "0.87 [0.84-0.89]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3A$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3A$roc_derivation$roc_obj
## Z = -4.5914, p-value = 4.402e-06
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.04520743 -0.01815825
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8361068   0.8677896
# MODEL 3B
results.model3B <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3B, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3B$model_stats
## NULL
results.model3B$derivation$auc
## [1] "0.89 [0.87-0.91]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3B$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3B$roc_derivation$roc_obj
## Z = -5.9401, p-value = 2.849e-09
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.06732729 -0.03392017
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8361068   0.8867305
# MODEL 3C
results.model3C <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3C, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3C$model_stats
## NULL
results.model3C$derivation$auc
## [1] "0.85 [0.82-0.87]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3C$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3C$roc_derivation$roc_obj
## Z = -2.8387, p-value = 0.00453
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.014070016 -0.002576424
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8361068   0.8444300
# MODEL 4
results.model4 <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var4, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model4$model_stats
## NULL
results.model4$derivation$auc
## [1] "0.9 [0.88-0.92]"
roc.test(results.model2$roc_derivation$roc_obj, results.model4$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model4$roc_derivation$roc_obj
## Z = -6.8675, p-value = 6.532e-12
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.08176242 -0.04545513
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8361068   0.8997156
# incremental between model 4 and model 3ABC
roc.test(results.model3A$roc_derivation$roc_obj, results.model4$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model3A$roc_derivation$roc_obj and results.model4$roc_derivation$roc_obj
## Z = -4.7942, p-value = 1.633e-06
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.04497781 -0.01887406
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8677896   0.8997156
roc.test(results.model3B$roc_derivation$roc_obj, results.model4$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model3B$roc_derivation$roc_obj and results.model4$roc_derivation$roc_obj
## Z = -3.6407, p-value = 0.0002719
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.019975469 -0.005994622
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8867305   0.8997156
roc.test(results.model3C$roc_derivation$roc_obj, results.model4$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model3C$roc_derivation$roc_obj and results.model4$roc_derivation$roc_obj
## Z = -6.3427, p-value = 2.257e-10
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.07236935 -0.03820176
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8444300   0.8997156

Tab11-incr_stepwise-LGE-death

# Assuming df_LGE is your initial dataset
df_selected <- df_all %>% 
  mutate_if(is.factor, as.numeric) %>% mutate(
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVESV_10 = CMR_LVESV/10,
    CMR_LVEDV_10 = CMR_LVEDV/10
  ) %>%
  select(outcome_death, outcome_FU_time_death,
         demo_age, demo_gender, demo_BMI, CV_risk_diabete, CV_risk_obesity, CV_risk_dyslipidemia,
         CV_risk_Smoking, history_med_MI, history_coronary_procedure, history_interv_PCI, history_interv_CABG, med_periph_atheroma, history_stroke, med_pacemaker, med_CKD, history_hospit_HF, history_AFib, clini_NYHA,
         clini_cardiac_rythm, CMR_LVEF_5, CMR_LVESV_10, CMR_LVEDV_10,
         CMR_LV_mass, CMR_RV_dysfunction) # CV_risk_HTA

# Define the Cox model formula
formula <- Surv(outcome_FU_time_death, outcome_death) ~ .

# Run stepwise Cox regression
stepwise_result <- stepwiseCox(
  formula = formula,
  data = df_selected,
  sle = 0.1,
  sls = 0.1,
  selection = "forward",  # Choose your selection method
  select = "SL" #,              # Choose your selection criterion
  # method = "Breslow"            # Choose your method for tie handling "Efron"
)

# View the results
summary(stepwise_result)
##                                        Length Class      Mode
## Summary of Parameters                   2     data.frame list
## Variables Type                          2     data.frame list
## Process of Selection                    6     data.frame list
## Selected Varaibles                     11     data.frame list
## Coefficients of the Selected Variables  6     data.frame list
var_select <- as.data.frame(t(stepwise_result$`Selected Varaibles`[1,]))$xModel
var_select
##  [1] "demo_gender"         "demo_age"            "CV_risk_diabete"    
##  [4] "CMR_RV_dysfunction"  "med_CKD"             "history_hospit_HF"  
##  [7] "CMR_LVEF_5"          "history_stroke"      "med_periph_atheroma"
## [10] "med_pacemaker"       "CV_risk_Smoking"
# View the results
summary(stepwise_result)
##                                        Length Class      Mode
## Summary of Parameters                   2     data.frame list
## Variables Type                          2     data.frame list
## Process of Selection                    6     data.frame list
## Selected Varaibles                     11     data.frame list
## Coefficients of the Selected Variables  6     data.frame list
var1 <- as.data.frame(t(stepwise_result$`Selected Varaibles`[1,]))$xModel # on prend les résultats du stepwise
var2 <- c(var1, "CMR_LGE_ischemic_extent_count")
var3A <- c(var2, "CMR_LGE_ischemic_transmurality")
var3B <- c(var2, "CMR_LGE_ischemic_location_4")
var3C <-  c(var2, "CMR_LGE_midwall_presence")
var4 <- c(var2, "CMR_LGE_ischemic_transmurality", "CMR_LGE_ischemic_location_4", "CMR_LGE_midwall_presence")

df_LGE <- df_LGE %>% mutate(
  time = outcome_FU_time_death,
  event = outcome_death,
  CMR_LVEF_5 = CMR_LVEF/5,
)%>% droplevels()

# MODEL 1
results.model1 <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var1, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model1$model_stats
## NULL
results.model1$derivation$auc
## [1] "0.7 [0.67-0.73]"
# MODEL 2
results.model2 <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var2, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model2$model_stats
## NULL
results.model2$derivation$auc
## [1] "0.84 [0.81-0.87]"
roc.test(results.model1$roc_derivation$roc_obj, results.model2$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model1$roc_derivation$roc_obj and results.model2$roc_derivation$roc_obj
## Z = -10.226, p-value < 2.2e-16
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.1659197 -0.1125463
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.6999564   0.8391894
# MODEL 3A
results.model3A <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3A, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3A$model_stats
## NULL
results.model3A$derivation$auc
## [1] "0.87 [0.84-0.89]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3A$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3A$roc_derivation$roc_obj
## Z = -4.3781, p-value = 1.197e-05
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.04311206 -0.01644824
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8391894   0.8689696
# MODEL 3B
results.model3B <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3B, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3B$model_stats
## NULL
results.model3B$derivation$auc
## [1] "0.89 [0.87-0.91]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3B$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3B$roc_derivation$roc_obj
## Z = -5.7315, p-value = 9.956e-09
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.06458015 -0.03166701
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8391894   0.8873130
# MODEL 3C
results.model3C <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3C, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3C$model_stats
## NULL
results.model3C$derivation$auc
## [1] "0.85 [0.82-0.88]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3C$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3C$roc_derivation$roc_obj
## Z = -2.9845, p-value = 0.00284
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.014321962 -0.002967746
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8391894   0.8478343
# MODEL 4
results.model4 <- CoxPredictScore(derivation = df_LGE, validation = df_LGE,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var4, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model4$model_stats
## NULL
results.model4$derivation$auc
## [1] "0.9 [0.88-0.92]"
roc.test(results.model2$roc_derivation$roc_obj, results.model4$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model4$roc_derivation$roc_obj
## Z = -6.6266, p-value = 3.435e-11
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.07912464 -0.04300285
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8391894   0.9002532

Figures

Fig8-Schoenfelds_residuals

df_selected <- df_LGE %>% 
  mutate(
    CMR_LVEF_5 = CMR_LVEF/5
  ) %>%
  select( 
    outcome_FU_time_death, outcome_death, 
    CMR_LGE_ischemic_extent_count,
    CMR_LGE_ischemic_transmurality,
    CMR_LGE_ischemic_location_4,
    CMR_LGE_midwall_presence,
    demo_age, demo_gender , demo_BMI , CV_risk_diabete , CV_risk_Smoking , CV_risk_dyslipidemia ,  history_hospit_HF , history_AFib , med_CKD , history_med_MI , CMR_LVEF_5
  ) %>% droplevels()

model_3 <- coxph(formula =  Surv(outcome_FU_time_death, outcome_death) ~ ., 
                 data = df_selected) 

cox.zph(model_3)
##                                   chisq df     p
## CMR_LGE_ischemic_extent_count  9.54e-01  1 0.329
## CMR_LGE_ischemic_transmurality 5.60e+00  2 0.061
## CMR_LGE_ischemic_location_4    1.34e+00  2 0.512
## CMR_LGE_midwall_presence       3.97e-01  1 0.529
## demo_age                       1.63e+00  1 0.202
## demo_gender                    1.67e-01  1 0.683
## demo_BMI                       1.89e-02  1 0.891
## CV_risk_diabete                6.91e-03  1 0.934
## CV_risk_Smoking                1.54e-01  1 0.695
## CV_risk_dyslipidemia           1.26e-05  1 0.997
## history_hospit_HF              1.57e-02  1 0.900
## history_AFib                   5.82e-01  1 0.446
## med_CKD                        2.42e-02  1 0.876
## history_med_MI                 8.76e-01  1 0.349
## CMR_LVEF_5                     4.70e+00  1 0.030
## GLOBAL                         2.05e+01 17 0.247
tbl_regression(model_3, exponentiate = TRUE, conf.level = 0.995, pvalue_fun = function(x) style_pvalue(x, digits = 3), label = list()) %>% bold_p() %>% 
  as_gt() %>% gt::tab_header(gt::md("Modèle 3 - risk litterature + LGE extent + granularity without multi"))
Modèle 3 - risk litterature + LGE extent + granularity without multi
Characteristic HR1 100% CI1 p-value
CMR_LGE_ischemic_extent_count 1.37 1.28, 1.48 <0.001
CMR_LGE_ischemic_transmurality


    B_Subendocardial<50% — —
    C_Subendocardial≥50% 2.21 1.53, 3.20 <0.001
    D_Transmural 2.92 1.94, 4.39 <0.001
CMR_LGE_ischemic_location_4


    B_Neither_anterior_nor_septal — —
    C_Anterior_without_septal 4.96 3.31, 7.44 <0.001
    D_Septal 7.14 4.92, 10.4 <0.001
CMR_LGE_midwall_presence


    A_No_midwall_LGE — —
    B_Presence_of_midwall_LGE 1.86 1.39, 2.50 <0.001
demo_age 1.01 1.00, 1.02 0.052
demo_gender


    No — —
    Yes 1.75 1.19, 2.57 <0.001
demo_BMI 1.00 0.97, 1.03 0.961
CV_risk_diabete


    No — —
    Yes 1.35 1.05, 1.73 <0.001
CV_risk_Smoking


    No — —
    Yes 1.13 0.83, 1.54 0.283
CV_risk_dyslipidemia


    No — —
    Yes 1.10 0.86, 1.40 0.297
history_hospit_HF


    No — —
    Yes 0.99 0.66, 1.48 0.942
history_AFib


    No — —
    Yes 0.78 0.53, 1.17 0.090
med_CKD


    No — —
    Yes 2.04 1.17, 3.54 <0.001
history_med_MI


    No — —
    Yes 0.98 0.76, 1.27 0.833
CMR_LVEF_5 0.99 0.89, 1.09 0.738
1 HR = Hazard Ratio, CI = Confidence Interval
c <- cox.zph(fit = model_3, transform ="km") 

# Extract the ggcoxzph plots
plots <- ggcoxzph(c)[1:5] # Assuming you have 5 groups to plot

plots
## $`1`

## 
## $`2`

## 
## $`3`

## 
## $`4`

## 
## $`5`

# Loop through the plots and save them
for (i in seq_along(plots)) {
  # Set up the filename with the current date and letter identifiers
  file_name <- paste0("Fig8-", LETTERS[i], "-Schoenfelds_residuals",Sys.Date(),".png")
  full_path <- here(figures_output_dir, file_name)
  
  # Save each plot
  ggsave(
    filename = full_path,
    plot = plots[[i]],
    width = 10,
    height = 6,
    units = "in",
    dpi = 300
  )
}

Fig9-LGE-KM-LGE_extent

# Data parameters
results <- createSurvivalPlot(
  data = df_LGE,
  compared_with = "CMR_LGE_ischemic_extent_categ",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  my_colors = c("#4292C6","#FF002B","#2C3E50"),
  my_legends = c("1-2 segments of ischemic LGE", "3-5 ischemic segments", "≥ 6 segments of ischemic"),
  confint_choosen = 0.995,
  mytitle = "Fig9-LGE-KM-LGE_extent"
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ CMR_LGE_ischemic_extent_categ"
results$HR
##                                                                  HR_CI p_value
## CMR_LGE_ischemic_extent_categC_3_5_segments      8.92 ( 4.86 - 16.39 )  <0.001
## CMR_LGE_ischemic_extent_categD_more6_segments 68.33 ( 36.98 - 126.27 )  <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig9-LGE-KM-LGE_extent_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig9-LGE-KM-LGE_extent_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

Fig10-LGE-KM-LGE_transm

# Data parameters
results <- createSurvivalPlot(
  data = df_LGE,
  compared_with = "CMR_LGE_ischemic_transmurality",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  my_colors = c("#4292C6","#FF002B","#2C3E50"),
  my_legends = c("Subendocardic <50%", "Subendocardic ≥ 50%", "Transmural"),
  confint_choosen = 0.995,
  mytitle = c("Fig10-LGE-KM-LGE_transm_risk")
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ CMR_LGE_ischemic_transmurality"
results$HR
##                                                                      HR_CI
## CMR_LGE_ischemic_transmuralityC_Subendocardial≥50%    3.57 ( 2.49 - 5.12 )
## CMR_LGE_ischemic_transmuralityD_Transmural         14.73 ( 10.17 - 21.34 )
##                                                    p_value
## CMR_LGE_ischemic_transmuralityC_Subendocardial≥50%  <0.001
## CMR_LGE_ischemic_transmuralityD_Transmural          <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig10-LGE-KM-LGE_transm_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig10-LGE-KM-LGE_transm_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

KM LGE location

Fig11A-LGE-KM-LGE_loca6

# Data parameters
results <- createSurvivalPlot(
  data = df_LGE,
  compared_with = "CMR_LGE_ischemic_location_6",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  my_colors = c("#006400", "darkblue", "darkviolet", "#FF0000", "#8B4513", "#000000"),
  my_legends = c("A_apical", "B_Inferior", "C_Lateral", "D_Anterior", "E_Septal", "Several_localization"),
  confint_choosen = 0.995,
  mytitle = c("Fig11A-LGE-KM-LGE_loca6"),
  show.CI = FALSE
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ CMR_LGE_ischemic_location_6"
results$HR
##                                                                    HR_CI
## CMR_LGE_ischemic_location_6Inferior                 1.09 ( 0.29 - 4.00 )
## CMR_LGE_ischemic_location_6Lateral                  2.50 ( 0.79 - 7.91 )
## CMR_LGE_ischemic_location_6Anterior                6.99 ( 2.16 - 22.60 )
## CMR_LGE_ischemic_location_6Septal                 22.50 ( 7.30 - 69.32 )
## CMR_LGE_ischemic_location_6Several_localization 60.36 ( 22.18 - 164.26 )
##                                                 p_value
## CMR_LGE_ischemic_location_6Inferior               0.858
## CMR_LGE_ischemic_location_6Lateral                0.026
## CMR_LGE_ischemic_location_6Anterior              <0.001
## CMR_LGE_ischemic_location_6Septal                <0.001
## CMR_LGE_ischemic_location_6Several_localization  <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig11A-LGE-KM-LGE_loca6_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig11A-LGE-KM-LGE_loca6_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

Fig11B-LGE-KM-LGE_loca4

# Data parameters
results <- createSurvivalPlot(
  data = df_LGE,
  compared_with = "CMR_LGE_ischemic_location_4",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  my_colors =  c("#4292C6","#FF002B","#2C3E50"),
  my_legends = c("Other location", "Anterior", "Septal"),
  confint_choosen = 0.995,
  mytitle = c("Fig11B-LGE-KM-LGE_loca4")
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ CMR_LGE_ischemic_location_4"
results$HR
##                                                                        HR_CI
## CMR_LGE_ischemic_location_4C_Anterior_without_septal   7.22 ( 4.87 - 10.70 )
## CMR_LGE_ischemic_location_4D_Septal                  21.91 ( 15.90 - 30.18 )
##                                                      p_value
## CMR_LGE_ischemic_location_4C_Anterior_without_septal  <0.001
## CMR_LGE_ischemic_location_4D_Septal                   <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig11B-LGE-KM-LGE_loca4_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig11B-LGE-KM-LGE_loca4_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

Fig12-LGE-KM-LGE_midwall

# Data parameters
results <- createSurvivalPlot(
  data = df_LGE,
  compared_with = "CMR_LGE_midwall_presence",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  my_colors =  c("#FF002B","#2C3E50"),
  my_legends = c("Ischemic LGE (excl)", "Isch and midwall LGE"),
  confint_choosen = 0.995,
  mytitle = c("Fig12-LGE-KM-LGE_midwall")
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ CMR_LGE_midwall_presence"
results$HR
##                  HR_CI p_value
## 1 3.13 ( 2.36 - 4.15 )  <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig12-LGE-KM-LGE_midwall_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig12-LGE-KM-LGE_midwall_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

Fig13-LGE-Stacked_Corr_var

library(ggplot2)
library(dplyr)
library(here)

# Function to create and save a ggplot
create_and_save_plot <- function(df, filename, title) {
  gg <- ggplot(df, aes(x = IschemicExtent, y = Count, fill = Pattern)) +
    geom_bar(stat = "identity", position = "fill") +
    scale_y_continuous(labels = scales::percent_format()) +
    scale_fill_manual(values = c("#009392","#f8766d","#7f7f7f")) +
    labs(title = title, x = "Ischemic Extent", y = "Percentage", fill = "Pattern") +
    theme_classic() +
    theme(legend.position = "none")
  
  print(gg)
  
  ggsave(filename = here(figures_output_dir, filename), plot = gg, width = 5, height = 6, units = "in", dpi = 600)
}

# Droplevels to clean up factors in df_LGE
df_LGE <- df_LGE %>% droplevels()

# Function to prepare data
prepare_data <- function(category) {
  table_data <- table(df_LGE$CMR_LGE_ischemic_extent_categ, category)
  df <- as.data.frame(table_data)
  names(df) <- c("IschemicExtent", "Pattern", "Count")
  # Reverse the order of 'Pattern' factor levels
  df$Pattern <- factor(df$Pattern, levels = rev(levels(df$Pattern)))
  # Datafra
  df <- df %>%
    group_by(IschemicExtent) %>%
    mutate(Percent = Count / sum(Count) * 100)
  print(df)
  return(df)
}

### By transmurality 
df_transmurality <- prepare_data(df_LGE$CMR_LGE_ischemic_transmurality)
## # A tibble: 9 × 4
## # Groups:   IschemicExtent [3]
##   IschemicExtent   Pattern              Count Percent
##   <fct>            <fct>                <int>   <dbl>
## 1 B_1_2_segments   B_Subendocardial<50%   729   52.4 
## 2 C_3_5_segments   B_Subendocardial<50%   922   47.2 
## 3 D_more6_segments B_Subendocardial<50%    47   19.1 
## 4 B_1_2_segments   C_Subendocardial≥50%   602   43.2 
## 5 C_3_5_segments   C_Subendocardial≥50%   842   43.1 
## 6 D_more6_segments C_Subendocardial≥50%   105   42.7 
## 7 B_1_2_segments   D_Transmural            61    4.38
## 8 C_3_5_segments   D_Transmural           189    9.68
## 9 D_more6_segments D_Transmural            94   38.2
create_and_save_plot(df_transmurality, "Fig13A-LGE-Stacked_Corr_LGE_transmurality.png", "Percentage Stacked Histogram of LGE Characteristics by Ischemic Extent - Transmurality")

### By location 
df_location <- prepare_data(df_LGE$CMR_LGE_ischemic_location_4)
## # A tibble: 9 × 4
## # Groups:   IschemicExtent [3]
##   IschemicExtent   Pattern                       Count Percent
##   <fct>            <fct>                         <int>   <dbl>
## 1 B_1_2_segments   B_Neither_anterior_nor_septal  1200   86.2 
## 2 C_3_5_segments   B_Neither_anterior_nor_septal  1425   73.0 
## 3 D_more6_segments B_Neither_anterior_nor_septal    37   15.0 
## 4 B_1_2_segments   C_Anterior_without_septal       129    9.27
## 5 C_3_5_segments   C_Anterior_without_septal       247   12.6 
## 6 D_more6_segments C_Anterior_without_septal        46   18.7 
## 7 B_1_2_segments   D_Septal                         63    4.53
## 8 C_3_5_segments   D_Septal                        281   14.4 
## 9 D_more6_segments D_Septal                        163   66.3
create_and_save_plot(df_location, "Fig13B-LGE-Stacked_Corr_LGE_location.png", "Percentage Stacked Histogram of LGE Characteristics by Ischemic Extent - Location")

### By midwall 
df_midwall <- prepare_data(df_LGE$CMR_LGE_midwall_presence)
## # A tibble: 6 × 4
## # Groups:   IschemicExtent [3]
##   IschemicExtent   Pattern                   Count Percent
##   <fct>            <fct>                     <int>   <dbl>
## 1 B_1_2_segments   A_No_midwall_LGE           1282   92.1 
## 2 C_3_5_segments   A_No_midwall_LGE           1774   90.8 
## 3 D_more6_segments A_No_midwall_LGE            181   73.6 
## 4 B_1_2_segments   B_Presence_of_midwall_LGE   110    7.90
## 5 C_3_5_segments   B_Presence_of_midwall_LGE   179    9.17
## 6 D_more6_segments B_Presence_of_midwall_LGE    65   26.4
create_and_save_plot(df_midwall, "Fig13C-LGE-Stacked_Corr_LGE_midwall.png", "Percentage Stacked Histogram of LGE Characteristics by Ischemic Extent - Midwall")

# LGE population with LGE ≤6 segments (N=3,440) ## Survival ### Tab12-univ-minus_LGE-death

df_selected <- df_LGE %>%
  mutate(
    surv.event = Surv(
      time = outcome_FU_time_death,
      event = outcome_death
    ),
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVEDV_5 = CMR_LVEDV/10,
    CMR_LVESV_5 = CMR_LVESV/10
  ) %>% filter(
    CMR_LGE_ischemic_extent_count <= 6
  )

Descr_table = createTable(compareGroups(
  surv.event ~ 
    demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
    CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
    
    history_med_MI  + history_coronary_procedure + history_interv_PCI + 
    history_interv_CABG + med_periph_atheroma + history_stroke + 
    med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
    clini_cardiac_rythm + 
    
   outcome_revascularisation_90days +
    
    CMR_LVEF_5 + CMR_LVEDV_5 + 
    CMR_LVESV_5 + CMR_LV_mass + CMR_RV_dysfunction + 
    
    CMR_LGE_presence_ischemic_and_midwall +
    
    CMR_LGE_ischemic_presence + 
    CMR_LGE_ischemic_extent_count +
    CMR_LGE_ischemic_extent_categ +
    CMR_LGE_ischemic_transmurality +
    CMR_LGE_ischemic_location_4 +
    
    CMR_LGE_ischemic_anterior + 
    CMR_LGE_ischemic_septal +
    CMR_LGE_ischemic_inferior +
    CMR_LGE_ischemic_lateral +
    CMR_LGE_ischemic_Apical +
    
    CMR_LGE_midwall_presence +
    CMR_LGE_midwall_extent_count + 
    CMR_LGE_midwall_extent_categ +
    CMR_LGE_midwall_location_3 + 
    CMR_LGE_midwall_location_4 +
    CMR_LGE_midwall_anterior +
    CMR_LGE_midwall_septal +
    CMR_LGE_midwall_inferior +
    CMR_LGE_midwall_lateral +
    CMR_LGE_midwall_apical,
  data= df_selected,
  method = 1, conf.level = 0.995),
  hide.no = "No",
  show.ratio=T, show.p.ratio = T) 

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `surv.event’
No event Event HR p.ratio p.overall
N=3033 N=407
demo_age 64.1 (11.7) 67.9 (11.5) 1.03 [1.01;1.04] <0.001 <0.001
demo_gender 2186 (72.1%) 368 (90.4%) 3.33 [2.07;5.34] <0.001 <0.001
demo_BMI 27.7 (5.37) 27.9 (5.71) 1.01 [0.98;1.03] 0.420 0.420
CV_risk_diabete 1134 (37.4%) 224 (55.0%) 1.90 [1.43;2.51] <0.001 <0.001
CV_risk_HTA 1626 (53.6%) 210 (51.6%) 0.93 [0.71;1.23] 0.491 0.491
CV_risk_obesity 835 (27.5%) 111 (27.3%) 1.00 [0.73;1.37] 0.979 0.977
CV_risk_dyslipidemia 1501 (49.5%) 213 (52.3%) 1.13 [0.86;1.49] 0.215 0.213
CV_risk_Smoking 635 (20.9%) 97 (23.8%) 1.14 [0.83;1.59] 0.247 0.248
history_med_MI 1162 (38.3%) 158 (38.8%) 1.02 [0.77;1.36] 0.821 0.821
history_coronary_procedure 2670 (88.0%) 364 (89.4%) 1.13 [0.72;1.78] 0.437 0.436
history_interv_PCI 196 (6.46%) 43 (10.6%) 1.56 [0.98;2.48] 0.007 0.007
history_interv_CABG 2507 (82.7%) 328 (80.6%) 0.89 [0.62;1.27] 0.360 0.360
med_periph_atheroma 156 (5.14%) 40 (9.83%) 1.90 [1.19;3.03] <0.001 <0.001
history_stroke 85 (2.80%) 23 (5.65%) 1.95 [1.07;3.56] 0.002 0.002
med_pacemaker 21 (0.69%) 2 (0.49%) 0.74 [0.10;5.42] 0.673 0.672
med_CKD 39 (1.29%) 24 (5.90%) 4.22 [2.34;7.63] <0.001 <0.001
history_hospit_HF 155 (5.11%) 48 (11.8%) 2.21 [1.43;3.40] <0.001 <0.001
history_AFib 207 (6.82%) 35 (8.60%) 1.25 [0.76;2.06] 0.213 0.207
clini_NYHA 385 (12.7%) 60 (14.7%) 1.09 [0.74;1.61] 0.543 0.541
clini_cardiac_rythm 197 (6.50%) 31 (7.62%) 1.15 [0.68;1.94] 0.469 0.463
outcome_revascularisation_90days 2518 (83.0%) 184 (45.2%) 0.22 [0.16;0.29] <0.001 0.000
CMR_LVEF_5 8.79 (1.14) 8.44 (1.28) 0.83 [0.75;0.92] <0.001 <0.001
CMR_LVEDV_5 10.2 (2.11) 10.5 (2.36) 1.04 [0.98;1.11] 0.040 0.040
CMR_LVESV_5 5.81 (1.74) 6.16 (1.93) 1.08 [1.01;1.16] 0.001 0.001
CMR_LV_mass 91.1 (19.6) 91.0 (19.1) 1.00 [0.99;1.01] 0.830 0.830
CMR_RV_dysfunction 89 (2.93%) 39 (9.58%) 3.09 [1.92;4.96] <0.001 <0.001
CMR_LGE_presence_ischemic_and_midwall 222 (7.32%) 94 (23.1%) 3.18 [2.28;4.43] <0.001 0.000
CMR_LGE_ischemic_presence: Presence_of_ischemic_LGE 3033 (100%) 407 (100%) Ref. Ref. .
CMR_LGE_ischemic_extent_count 2.72 (1.25) 4.33 (1.27) 2.24 [2.00;2.51] <0.001 <0.001
CMR_LGE_ischemic_extent_categ: 0.000
B_1_2_segments 1369 (45.1%) 23 (5.65%) Ref. Ref.
C_3_5_segments 1659 (54.7%) 294 (72.2%) 8.91 [4.85;16.4] <0.001
D_more6_segments 5 (0.16%) 90 (22.1%) 61.4 [31.8;119] <0.001
CMR_LGE_ischemic_transmurality: 0.000
B_Subendocardial<50% 1613 (53.2%) 52 (12.8%) Ref. Ref.
C_Subendocardial≥50% 1287 (42.4%) 199 (48.9%) 4.27 [2.76;6.62] <0.001
D_Transmural 133 (4.39%) 156 (38.3%) 18.8 [12.0;29.4] <0.001
CMR_LGE_ischemic_location_4: 0.000
B_Neither_anterior_nor_septal 2557 (84.3%) 87 (21.4%) Ref. Ref.
C_Anterior_without_septal 316 (10.4%) 74 (18.2%) 5.99 [3.84;9.34] <0.001
D_Septal 160 (5.28%) 246 (60.4%) 21.6 [15.2;30.7] <0.001
CMR_LGE_ischemic_anterior 382 (12.6%) 279 (68.6%) 10.1 [7.48;13.6] <0.001 0.000
CMR_LGE_ischemic_septal 160 (5.28%) 246 (60.4%) 13.3 [10.0;17.8] <0.001 0.000
CMR_LGE_ischemic_inferior 1093 (36.0%) 89 (21.9%) 0.54 [0.39;0.76] <0.001 <0.001
CMR_LGE_ischemic_lateral 962 (31.7%) 158 (38.8%) 1.27 [0.95;1.69] 0.020 0.020
CMR_LGE_ischemic_Apical 872 (28.8%) 214 (52.6%) 2.44 [1.84;3.22] <0.001 0.000
CMR_LGE_midwall_presence: 0.000
A_No_midwall_LGE 2811 (92.7%) 313 (76.9%) Ref. Ref.
B_Presence_of_midwall_LGE 222 (7.32%) 94 (23.1%) 3.18 [2.28;4.43] <0.001
CMR_LGE_midwall_extent_count 0.08 (0.28) 0.35 (0.70) 2.52 [2.06;3.07] <0.001 <0.001
CMR_LGE_midwall_extent_categ: 0.000
None 2811 (92.7%) 313 (76.9%) Ref. Ref.
Low_=1 212 (6.99%) 49 (12.0%) 2.04 [1.32;3.13] <0.001
High_>1 10 (0.33%) 45 (11.1%) 8.51 [5.39;13.4] <0.001
CMR_LGE_midwall_location_3: 0.000
No_midwall_LGE 2811 (92.7%) 313 (76.9%) Ref. Ref.
Midwall_LGE_not_at_risk 178 (5.87%) 36 (8.85%) 1.67 [1.02;2.75] 0.004
At_risk_midwall_LGE_(septal_and/or_lateral) 44 (1.45%) 58 (14.3%) 7.00 [4.68;10.5] <0.001
CMR_LGE_midwall_location_4: 0.000
No_midwall_LGE 2811 (92.7%) 313 (76.9%) Ref. Ref.
Midwall_LGE_not_at_risk 178 (5.87%) 36 (8.85%) 1.67 [1.02;2.75] 0.004
Lateral_midwall_LGE 16 (0.53%) 34 (8.35%) 9.35 [5.62;15.5] <0.001
Septal_Midwall_LGE 28 (0.92%) 24 (5.90%) 5.16 [2.84;9.36] <0.001
CMR_LGE_midwall_anterior 82 (2.70%) 13 (3.19%) 1.14 [0.52;2.51] 0.645 0.646
CMR_LGE_midwall_septal 28 (0.92%) 24 (5.90%) 4.54 [2.51;8.20] <0.001 <0.001
CMR_LGE_midwall_inferior 54 (1.78%) 28 (6.88%) 3.67 [2.12;6.36] <0.001 <0.001
CMR_LGE_midwall_lateral 16 (0.53%) 39 (9.58%) 8.74 [5.44;14.0] <0.001 0.000
CMR_LGE_midwall_apical 43 (1.42%) 9 (2.21%) 1.28 [0.48;3.40] 0.483 0.464
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab12-univ-minus_LGE-death-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Tab13-multi_tradi-minus_LGE-death

df <- df_LGE %>% filter(
    CMR_LGE_ischemic_extent_count <= 6
  ) %>% mutate(
  event = outcome_death,
  time = outcome_FU_time_death,
  CMR_LVEF_5 = CMR_LVEF/5
) %>% select(
  event, time,
  demo_age, demo_gender, demo_BMI , CV_risk_diabete , CV_risk_Smoking , CV_risk_dyslipidemia ,  history_hospit_HF, history_AFib, med_CKD, history_med_MI , CMR_LVEF_5, CMR_LGE_ischemic_extent_count, CMR_LGE_ischemic_transmurality, CMR_LGE_ischemic_location_4, CMR_LGE_midwall_presence, outcome_revascularisation_90days) %>% droplevels()

#### TABLE 

## Model 1
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LVEF_5))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 1", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 1
Coefficients_CI HR_CI p_value
demo_age 0.03 ( 0.02 - 0.04 ) 1.03 ( 1.02 - 1.04 ) <0.001
demo_genderYes 1.17 ( 0.69 - 1.64 ) 3.21 ( 1.99 - 5.17 ) <0.001
demo_BMI 0.01 ( -0.02 - 0.04 ) 1.01 ( 0.98 - 1.04 ) 0.397
CV_risk_diabeteYes 0.53 ( 0.24 - 0.83 ) 1.71 ( 1.27 - 2.28 ) <0.001
CV_risk_SmokingYes 0.31 ( -0.04 - 0.66 ) 1.36 ( 0.96 - 1.93 ) 0.013
CV_risk_dyslipidemiaYes 0.02 ( -0.26 - 0.31 ) 1.02 ( 0.77 - 1.36 ) 0.807
history_hospit_HFYes 0.48 ( 0.02 - 0.95 ) 1.62 ( 1.02 - 2.58 ) 0.003
history_AFibYes -0.19 ( -0.70 - 0.32 ) 0.83 ( 0.50 - 1.38 ) 0.302
med_CKDYes 1.10 ( 0.48 - 1.72 ) 3.00 ( 1.62 - 5.57 ) <0.001
history_med_MIYes -0.00 ( -0.30 - 0.29 ) 1.00 ( 0.74 - 1.34 ) 0.982
CMR_LVEF_5 -0.08 ( -0.19 - 0.03 ) 0.93 ( 0.83 - 1.04 ) 0.053
write.csv(data, file = here("outputs", "csv_files","minus_LGE_pop_model1_trad.csv"), append = FALSE)

## Model 2
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 2", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 2
Coefficients_CI HR_CI p_value
demo_age 0.02 ( 0.01 - 0.03 ) 1.02 ( 1.01 - 1.03 ) <0.001
demo_genderYes 0.99 ( 0.51 - 1.47 ) 2.69 ( 1.67 - 4.35 ) <0.001
demo_BMI 0.01 ( -0.02 - 0.04 ) 1.01 ( 0.98 - 1.04 ) 0.357
CV_risk_diabeteYes 0.42 ( 0.13 - 0.71 ) 1.52 ( 1.14 - 2.03 ) <0.001
CV_risk_SmokingYes 0.35 ( 0.00 - 0.71 ) 1.43 ( 1.00 - 2.03 ) 0.005
CV_risk_dyslipidemiaYes 0.02 ( -0.26 - 0.30 ) 1.02 ( 0.77 - 1.35 ) 0.852
history_hospit_HFYes 0.32 ( -0.16 - 0.79 ) 1.37 ( 0.85 - 2.21 ) 0.062
history_AFibYes -0.11 ( -0.63 - 0.41 ) 0.90 ( 0.54 - 1.51 ) 0.562
med_CKDYes 0.87 ( 0.26 - 1.49 ) 2.40 ( 1.30 - 4.43 ) <0.001
history_med_MIYes 0.02 ( -0.27 - 0.32 ) 1.02 ( 0.76 - 1.38 ) 0.832
CMR_LVEF_5 -0.05 ( -0.17 - 0.06 ) 0.95 ( 0.84 - 1.07 ) 0.207
CMR_LGE_ischemic_extent_count 0.73 ( 0.62 - 0.85 ) 2.08 ( 1.86 - 2.33 ) <0.001
## Model 3A
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_transmurality))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 3A", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 3A
Coefficients_CI HR_CI p_value
demo_age 0.01 ( -0.00 - 0.03 ) 1.01 ( 1.00 - 1.03 ) 0.008
demo_genderYes 0.88 ( 0.40 - 1.36 ) 2.41 ( 1.49 - 3.91 ) <0.001
demo_BMI 0.00 ( -0.03 - 0.03 ) 1.00 ( 0.97 - 1.03 ) 0.833
CV_risk_diabeteYes 0.47 ( 0.17 - 0.76 ) 1.59 ( 1.19 - 2.13 ) <0.001
CV_risk_SmokingYes 0.21 ( -0.14 - 0.57 ) 1.24 ( 0.87 - 1.76 ) 0.089
CV_risk_dyslipidemiaYes 0.01 ( -0.27 - 0.30 ) 1.01 ( 0.76 - 1.34 ) 0.893
history_hospit_HFYes 0.18 ( -0.31 - 0.68 ) 1.20 ( 0.73 - 1.97 ) 0.300
history_AFibYes -0.35 ( -0.88 - 0.18 ) 0.70 ( 0.41 - 1.19 ) 0.061
med_CKDYes 0.88 ( 0.25 - 1.50 ) 2.41 ( 1.29 - 4.50 ) <0.001
history_med_MIYes 0.01 ( -0.29 - 0.31 ) 1.01 ( 0.75 - 1.36 ) 0.945
CMR_LVEF_5 -0.03 ( -0.15 - 0.09 ) 0.97 ( 0.86 - 1.10 ) 0.496
CMR_LGE_ischemic_extent_count 0.59 ( 0.48 - 0.70 ) 1.81 ( 1.62 - 2.02 ) <0.001
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 1.30 ( 0.85 - 1.74 ) 3.65 ( 2.35 - 5.67 ) <0.001
CMR_LGE_ischemic_transmuralityD_Transmural 2.18 ( 1.71 - 2.65 ) 8.83 ( 5.52 - 14.12 ) <0.001
## Model 3B
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count, CMR_LGE_ischemic_location_4))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 3B", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 3B
Coefficients_CI HR_CI p_value
demo_age 0.02 ( 0.00 - 0.03 ) 1.02 ( 1.00 - 1.03 ) <0.001
demo_genderYes 0.75 ( 0.26 - 1.24 ) 2.11 ( 1.30 - 3.44 ) <0.001
demo_BMI 0.01 ( -0.02 - 0.04 ) 1.01 ( 0.98 - 1.04 ) 0.207
CV_risk_diabeteYes 0.41 ( 0.12 - 0.71 ) 1.51 ( 1.13 - 2.03 ) <0.001
CV_risk_SmokingYes 0.23 ( -0.13 - 0.59 ) 1.26 ( 0.88 - 1.80 ) 0.071
CV_risk_dyslipidemiaYes 0.07 ( -0.22 - 0.35 ) 1.07 ( 0.81 - 1.42 ) 0.511
history_hospit_HFYes 0.10 ( -0.40 - 0.59 ) 1.10 ( 0.67 - 1.80 ) 0.584
history_AFibYes -0.48 ( -1.00 - 0.04 ) 0.62 ( 0.37 - 1.05 ) 0.010
med_CKDYes 0.85 ( 0.22 - 1.48 ) 2.34 ( 1.25 - 4.39 ) <0.001
history_med_MIYes -0.09 ( -0.39 - 0.21 ) 0.91 ( 0.68 - 1.23 ) 0.390
CMR_LVEF_5 0.00 ( -0.12 - 0.12 ) 1.00 ( 0.89 - 1.13 ) 0.967
CMR_LGE_ischemic_extent_count 0.42 ( 0.31 - 0.54 ) 1.52 ( 1.36 - 1.71 ) <0.001
CMR_LGE_ischemic_location_4C_Anterior_without_septal 1.54 ( 1.09 - 1.99 ) 4.67 ( 2.97 - 7.32 ) <0.001
CMR_LGE_ischemic_location_4D_Septal 2.40 ( 2.01 - 2.78 ) 11.00 ( 7.48 - 16.16 ) <0.001
## Model 3C
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count, CMR_LGE_midwall_presence))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 3C", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 3C
Coefficients_CI HR_CI p_value
demo_age 0.02 ( 0.00 - 0.03 ) 1.02 ( 1.00 - 1.03 ) <0.001
demo_genderYes 1.02 ( 0.54 - 1.50 ) 2.77 ( 1.71 - 4.47 ) <0.001
demo_BMI 0.01 ( -0.02 - 0.04 ) 1.01 ( 0.98 - 1.04 ) 0.526
CV_risk_diabeteYes 0.38 ( 0.09 - 0.67 ) 1.46 ( 1.09 - 1.96 ) <0.001
CV_risk_SmokingYes 0.40 ( 0.05 - 0.75 ) 1.49 ( 1.05 - 2.12 ) 0.001
CV_risk_dyslipidemiaYes 0.09 ( -0.19 - 0.38 ) 1.10 ( 0.83 - 1.46 ) 0.358
history_hospit_HFYes 0.38 ( -0.09 - 0.86 ) 1.46 ( 0.91 - 2.35 ) 0.024
history_AFibYes 0.01 ( -0.50 - 0.53 ) 1.01 ( 0.60 - 1.70 ) 0.948
med_CKDYes 0.84 ( 0.23 - 1.46 ) 2.33 ( 1.26 - 4.28 ) <0.001
history_med_MIYes 0.00 ( -0.30 - 0.30 ) 1.00 ( 0.74 - 1.35 ) 0.989
CMR_LVEF_5 -0.04 ( -0.15 - 0.08 ) 0.96 ( 0.86 - 1.08 ) 0.378
CMR_LGE_ischemic_extent_count 0.71 ( 0.60 - 0.83 ) 2.04 ( 1.83 - 2.28 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.94 ( 0.60 - 1.28 ) 2.56 ( 1.82 - 3.59 ) <0.001
## Model 4
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event: CMR_LGE_midwall_presence))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 4", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 4
Coefficients_CI HR_CI p_value
demo_age 0.01 ( -0.00 - 0.02 ) 1.01 ( 1.00 - 1.02 ) 0.034
demo_genderYes 0.66 ( 0.17 - 1.15 ) 1.93 ( 1.18 - 3.16 ) <0.001
demo_BMI 0.01 ( -0.02 - 0.04 ) 1.01 ( 0.98 - 1.04 ) 0.536
CV_risk_diabeteYes 0.42 ( 0.13 - 0.72 ) 1.53 ( 1.14 - 2.05 ) <0.001
CV_risk_SmokingYes 0.20 ( -0.16 - 0.56 ) 1.22 ( 0.85 - 1.75 ) 0.121
CV_risk_dyslipidemiaYes 0.11 ( -0.18 - 0.40 ) 1.12 ( 0.84 - 1.49 ) 0.283
history_hospit_HFYes 0.16 ( -0.35 - 0.66 ) 1.17 ( 0.71 - 1.94 ) 0.384
history_AFibYes -0.44 ( -0.96 - 0.09 ) 0.64 ( 0.38 - 1.09 ) 0.019
med_CKDYes 0.82 ( 0.19 - 1.45 ) 2.27 ( 1.21 - 4.26 ) <0.001
history_med_MIYes -0.10 ( -0.40 - 0.20 ) 0.91 ( 0.67 - 1.23 ) 0.371
CMR_LVEF_5 0.03 ( -0.09 - 0.16 ) 1.03 ( 0.91 - 1.17 ) 0.448
CMR_LGE_ischemic_extent_count 0.36 ( 0.24 - 0.47 ) 1.43 ( 1.27 - 1.60 ) <0.001
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 1.03 ( 0.59 - 1.48 ) 2.81 ( 1.80 - 4.41 ) <0.001
CMR_LGE_ischemic_transmuralityD_Transmural 1.43 ( 0.94 - 1.92 ) 4.19 ( 2.56 - 6.84 ) <0.001
CMR_LGE_ischemic_location_4C_Anterior_without_septal 1.49 ( 1.03 - 1.94 ) 4.42 ( 2.81 - 6.96 ) <0.001
CMR_LGE_ischemic_location_4D_Septal 2.06 ( 1.66 - 2.47 ) 7.89 ( 5.27 - 11.80 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.59 ( 0.24 - 0.94 ) 1.81 ( 1.27 - 2.57 ) <0.001
write.csv(data, file = here("outputs", "csv_files","minus_LGE_pop_model4_trad.csv"), append = FALSE)

## Model 5
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event: outcome_revascularisation_90days))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 4", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 4
Coefficients_CI HR_CI p_value
demo_age 0.01 ( -0.01 - 0.02 ) 1.01 ( 0.99 - 1.02 ) 0.115
demo_genderYes 0.66 ( 0.17 - 1.15 ) 1.93 ( 1.18 - 3.15 ) <0.001
demo_BMI 0.01 ( -0.02 - 0.04 ) 1.01 ( 0.98 - 1.04 ) 0.480
CV_risk_diabeteYes 0.42 ( 0.13 - 0.72 ) 1.53 ( 1.14 - 2.05 ) <0.001
CV_risk_SmokingYes 0.18 ( -0.18 - 0.54 ) 1.20 ( 0.84 - 1.72 ) 0.153
CV_risk_dyslipidemiaYes 0.10 ( -0.19 - 0.39 ) 1.10 ( 0.83 - 1.47 ) 0.334
history_hospit_HFYes 0.15 ( -0.35 - 0.65 ) 1.16 ( 0.70 - 1.92 ) 0.401
history_AFibYes -0.41 ( -0.94 - 0.11 ) 0.66 ( 0.39 - 1.12 ) 0.028
med_CKDYes 0.81 ( 0.18 - 1.44 ) 2.25 ( 1.20 - 4.23 ) <0.001
history_med_MIYes -0.10 ( -0.40 - 0.20 ) 0.90 ( 0.67 - 1.22 ) 0.339
CMR_LVEF_5 0.04 ( -0.09 - 0.16 ) 1.04 ( 0.91 - 1.17 ) 0.430
CMR_LGE_ischemic_extent_count 0.35 ( 0.24 - 0.47 ) 1.42 ( 1.27 - 1.60 ) <0.001
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 1.01 ( 0.56 - 1.46 ) 2.75 ( 1.75 - 4.31 ) <0.001
CMR_LGE_ischemic_transmuralityD_Transmural 1.20 ( 0.64 - 1.77 ) 3.34 ( 1.90 - 5.86 ) <0.001
CMR_LGE_ischemic_location_4C_Anterior_without_septal 1.47 ( 1.02 - 1.93 ) 4.37 ( 2.78 - 6.88 ) <0.001
CMR_LGE_ischemic_location_4D_Septal 2.05 ( 1.65 - 2.45 ) 7.77 ( 5.19 - 11.63 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.58 ( 0.23 - 0.93 ) 1.79 ( 1.26 - 2.54 ) <0.001
outcome_revascularisation_90daysYes -0.31 ( -0.71 - 0.08 ) 0.73 ( 0.49 - 1.09 ) 0.026
## MODELS MULTI NESTED
var_base = c("demo_age", "demo_gender" , "demo_BMI" , "CV_risk_diabete" , "CV_risk_Smoking" , "CV_risk_dyslipidemia" ,  "history_hospit_HF", "history_AFib" , "med_CKD" , "history_med_MI" , "CMR_LVEF_5")

### Nested 4
table <- uni_multi_function(
  df = df, 
  event = "event",
  time = "time", 
  var_base = var_base, 
  var_added = c("CMR_LGE_ischemic_extent_count", "CMR_LGE_ischemic_transmurality","CMR_LGE_ischemic_location_4",
                "CMR_LGE_midwall_presence", "outcome_revascularisation_90days"))

# export in html
knitr::kable(table, caption = "Model full - granularity until revasc (minus LGE pop = 3,440)", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model full - granularity until revasc (minus LGE pop = 3,440)
Variable Univariate_Analysis model_multi_1 model_multi_2 model_multi_3 model_multi_4 model_multi_5 model_multi_6
demo_age 1.03 (1.01-1.04), p=0.000 1.03 (1.02-1.04), p=0.000 1.02 (1.01-1.03), p=0.000 1.01 (1.00-1.03), p=0.008 1.01 (1.00-1.03), p=0.016 1.01 (1.00-1.02), p=0.034 1.01 (0.99-1.02), p=0.115
demo_genderYes 3.33 (2.07-5.34), p=0.000 3.21 (1.99-5.17), p=0.000 2.69 (1.67-4.35), p=0.000 2.41 (1.49-3.91), p=0.000 1.93 (1.18-3.16), p=0.000 1.93 (1.18-3.16), p=0.000 1.93 (1.18-3.15), p=0.000
demo_BMI 1.01 (0.98-1.03), p=0.420 1.01 (0.98-1.04), p=0.397 1.01 (0.98-1.04), p=0.357 1.00 (0.97-1.03), p=0.833 1.01 (0.98-1.04), p=0.433 1.01 (0.98-1.04), p=0.536 1.01 (0.98-1.04), p=0.480
CV_risk_diabeteYes 1.90 (1.43-2.51), p=0.000 1.71 (1.27-2.28), p=0.000 1.52 (1.14-2.03), p=0.000 1.59 (1.19-2.13), p=0.000 1.57 (1.17-2.11), p=0.000 1.53 (1.14-2.05), p=0.000 1.53 (1.14-2.05), p=0.000
CV_risk_SmokingYes 1.14 (0.83-1.59), p=0.247 1.36 (0.96-1.93), p=0.013 1.43 (1.00-2.03), p=0.005 1.24 (0.87-1.76), p=0.089 1.16 (0.81-1.66), p=0.243 1.22 (0.85-1.75), p=0.121 1.20 (0.84-1.72), p=0.153
CV_risk_dyslipidemiaYes 1.13 (0.86-1.49), p=0.215 1.02 (0.77-1.36), p=0.807 1.02 (0.77-1.35), p=0.852 1.01 (0.76-1.34), p=0.893 1.04 (0.78-1.38), p=0.697 1.12 (0.84-1.49), p=0.283 1.10 (0.83-1.47), p=0.334
history_hospit_HFYes 2.21 (1.43-3.40), p=0.000 1.62 (1.02-2.58), p=0.003 1.37 (0.85-2.21), p=0.062 1.20 (0.73-1.97), p=0.300 1.04 (0.62-1.72), p=0.843 1.17 (0.71-1.94), p=0.384 1.16 (0.70-1.92), p=0.401
history_AFibYes 1.25 (0.76-2.06), p=0.213 0.83 (0.50-1.38), p=0.302 0.90 (0.54-1.51), p=0.562 0.70 (0.41-1.19), p=0.061 0.58 (0.35-0.99), p=0.004 0.64 (0.38-1.09), p=0.019 0.66 (0.39-1.12), p=0.028
med_CKDYes 4.22 (2.34-7.63), p=0.000 3.00 (1.62-5.57), p=0.000 2.40 (1.30-4.43), p=0.000 2.41 (1.29-4.50), p=0.000 2.29 (1.22-4.31), p=0.000 2.27 (1.21-4.26), p=0.000 2.25 (1.20-4.23), p=0.000
history_med_MIYes 1.02 (0.77-1.36), p=0.821 1.00 (0.74-1.34), p=0.982 1.02 (0.76-1.38), p=0.832 1.01 (0.75-1.36), p=0.945 0.93 (0.69-1.26), p=0.518 0.91 (0.67-1.23), p=0.371 0.90 (0.67-1.22), p=0.339
CMR_LVEF_5 0.83 (0.75-0.92), p=0.000 0.93 (0.83-1.04), p=0.053 0.95 (0.84-1.07), p=0.207 0.97 (0.86-1.10), p=0.496 1.02 (0.90-1.16), p=0.679 1.03 (0.91-1.17), p=0.448 1.04 (0.91-1.17), p=0.430
CMR_LGE_ischemic_extent_count 2.24 (2.00-2.51), p=0.000 NA 2.08 (1.86-2.33), p=0.000 1.81 (1.62-2.02), p=0.000 1.43 (1.28-1.61), p=0.000 1.43 (1.27-1.60), p=0.000 1.42 (1.27-1.60), p=0.000
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 4.27 (2.76-6.62), p=0.000 NA NA 3.65 (2.35-5.67), p=0.000 2.94 (1.88-4.60), p=0.000 2.81 (1.80-4.41), p=0.000 2.75 (1.75-4.31), p=0.000
CMR_LGE_ischemic_transmuralityD_Transmural 18.76 (11.96-29.43), p=0.000 NA NA 8.83 (5.52-14.12), p=0.000 4.57 (2.81-7.44), p=0.000 4.19 (2.56-6.84), p=0.000 3.34 (1.90-5.86), p=0.000
CMR_LGE_ischemic_location_4C_Anterior_without_septal 5.99 (3.84-9.34), p=0.000 NA NA NA 4.41 (2.81-6.94), p=0.000 4.42 (2.81-6.96), p=0.000 4.37 (2.78-6.88), p=0.000
CMR_LGE_ischemic_location_4D_Septal 21.63 (15.23-30.72), p=0.000 NA NA NA 8.08 (5.41-12.09), p=0.000 7.89 (5.27-11.80), p=0.000 7.77 (5.19-11.63), p=0.000
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 3.18 (2.28-4.43), p=0.000 NA NA NA NA 1.81 (1.27-2.57), p=0.000 1.79 (1.26-2.54), p=0.000
outcome_revascularisation_90daysYes 0.22 (0.16-0.29), p=0.000 NA NA NA NA NA 0.73 (0.49-1.09), p=0.026
# Export in word
ft <- flextable(table)
ft <- set_table_properties(ft, layout = "autofit")
doc <- read_docx() %>%
  body_add_par("Model 4 - LGE pop (N=3,440", style = "heading 1") %>%
  body_add_flextable(ft)
print(doc, target = here(tables_output_dir,paste0("Tab13-multi_tradi-minus_LGE-death-",Sys.Date(), ".docx")))

Tab14-incr-minus_LGE-death

var1 <- c("demo_age", "demo_gender" , "demo_BMI" , "CV_risk_diabete" , "CV_risk_Smoking" , "CV_risk_dyslipidemia" ,  "history_hospit_HF", "history_AFib" , "med_CKD" , "history_med_MI" , "CMR_LVEF_5")
var2 <- c(var1, "CMR_LGE_ischemic_extent_count")
var3A <- c(var2, "CMR_LGE_ischemic_transmurality")
var3B <- c(var2, "CMR_LGE_ischemic_location_4")
var3C <-  c(var2, "CMR_LGE_midwall_presence")
var4 <- c(var2, "CMR_LGE_ischemic_transmurality", "CMR_LGE_ischemic_location_4", "CMR_LGE_midwall_presence")

df_LGE_minus <- df_LGE %>% filter(CMR_LGE_ischemic_extent_count <= 6) %>% mutate(
  time = outcome_FU_time_death,
  event = outcome_death,
  CMR_LVEF = CMR_LVEF/5
)%>% droplevels()

# MODEL 1
results.model1 <- CoxPredictScore(derivation = df_LGE_minus, validation = df_LGE_minus,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var1, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model1$model_stats
## NULL
results.model1$derivation$auc
## [1] "0.68 [0.64-0.72]"
# MODEL 2
results.model2 <- CoxPredictScore(derivation = df_LGE_minus, validation = df_LGE_minus,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var2, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model2$model_stats
## NULL
results.model2$derivation$auc
## [1] "0.8 [0.75-0.84]"
roc.test(results.model1$roc_derivation$roc_obj, results.model2$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model1$roc_derivation$roc_obj and results.model2$roc_derivation$roc_obj
## Z = -7.3726, p-value = 1.674e-13
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.15163774 -0.08794567
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.6810355   0.8008272
# MODEL 3A
results.model3A <- CoxPredictScore(derivation = df_LGE_minus, validation = df_LGE_minus,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3A, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3A$model_stats
## NULL
results.model3A$derivation$auc
## [1] "0.85 [0.83-0.88]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3A$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3A$roc_derivation$roc_obj
## Z = -4.9818, p-value = 6.298e-07
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.06988273 -0.03042105
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8008272   0.8509791
# MODEL 3B
results.model3B <- CoxPredictScore(derivation = df_LGE_minus, validation = df_LGE_minus,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3B, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3B$model_stats
## NULL
results.model3B$derivation$auc
## [1] "0.88 [0.86-0.91]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3B$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3B$roc_derivation$roc_obj
## Z = -6.9694, p-value = 3.182e-12
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.10112977 -0.05673473
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8008272   0.8797594
# MODEL 3C
results.model3C <- CoxPredictScore(derivation = df_LGE_minus, validation = df_LGE_minus,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3C, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3C$model_stats
## NULL
results.model3C$derivation$auc
## [1] "0.81 [0.77-0.85]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3C$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3C$roc_derivation$roc_obj
## Z = -2.5202, p-value = 0.01173
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.020323540 -0.002541511
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8008272   0.8122597
# MODEL 4
results.model4 <- CoxPredictScore(derivation = df_LGE_minus, validation = df_LGE_minus,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var4, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model4$model_stats
## NULL
results.model4$derivation$auc
## [1] "0.9 [0.88-0.92]"
roc.test(results.model2$roc_derivation$roc_obj, results.model4$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model4$roc_derivation$roc_obj
## Z = -7.9664, p-value = 1.634e-15
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.12198186 -0.07381117
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8008272   0.8987237

MACE population (N=1,500)

Descriptive

Tab15-descr-MACEpop-death

df_selected <- df_MACE %>%
  mutate(
    outcome_death = as.factor(outcome_death),
    outcome_MACE = as.factor(outcome_MACE),
    outcome_MACE_CV_death = as.factor(outcome_MACE_CV_death),
    outcome_MACE_NonFatal_MI = as.factor(outcome_MACE_NonFatal_MI),
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVEDV_5 = CMR_LVEDV/10,
    CMR_LVESV_5 = CMR_LVESV/10
  ) 

Descr_table = createTable(compareGroups(
      outcome_death ~ 
        outcome_death + outcome_MACE + outcome_MACE_CV_death + outcome_MACE_NonFatal_MI +
        demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
        CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
        
        history_med_MI  + history_coronary_procedure + history_interv_PCI + 
        history_interv_CABG + med_periph_atheroma + history_stroke + 
        med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
        clini_cardiac_rythm + 
        
        CMR_LVEF_5 + CMR_LVEDV_5 + 
        CMR_LVESV_5 + CMR_LV_mass + CMR_RV_dysfunction + 
        
        CMR_LGE_ischemic_presence + 
        CMR_LGE_ischemic_extent_count +
        CMR_LGE_ischemic_extent_categ + 
        CMR_LGE_ischemic_transmurality +
        CMR_LGE_ischemic_location_4 +
        
        CMR_LGE_ischemic_anterior + 
        CMR_LGE_ischemic_septal +
        CMR_LGE_ischemic_inferior +
        CMR_LGE_ischemic_lateral +
        CMR_LGE_ischemic_Apical +
        
        CMR_LGE_midwall_presence +
      
        CMR_LGE_presence_ischemic_and_midwall +
        
        outcome_revascularisation_90days,
  data= df_selected,
  method = 1, conf.level = 0.995), # Pvalue
  hide.no = "No", show.all = TRUE, show.p.overall = TRUE) # bug avec le hide

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `outcome_death’
[ALL] 0 1 p.overall
N=1500 N=1273 N=227
outcome_death: 0.000
0 1273 (84.9%) 1273 (100%) 0 (0.00%)
1 227 (15.1%) 0 (0.00%) 227 (100%)
outcome_MACE: <0.001
0 1227 (81.8%) 1207 (94.8%) 20 (8.81%)
1 273 (18.2%) 66 (5.18%) 207 (91.2%)
outcome_MACE_CV_death: <0.001
0 1286 (86.5%) 1269 (100%) 17 (7.83%)
1 200 (13.5%) 0 (0.00%) 200 (92.2%)
outcome_MACE_NonFatal_MI: 0.302
0 1414 (95.2%) 1204 (94.9%) 210 (96.8%)
1 72 (4.85%) 65 (5.12%) 7 (3.23%)
demo_age 64.2 (11.8) 63.3 (11.7) 69.1 (11.2) <0.001
demo_gender 1123 (74.9%) 924 (72.6%) 199 (87.7%) <0.001
demo_BMI 27.7 (5.47) 27.7 (5.52) 27.6 (5.20) 0.889
CV_risk_diabete 547 (36.5%) 417 (32.8%) 130 (57.3%) <0.001
CV_risk_HTA 650 (43.3%) 534 (41.9%) 116 (51.1%) 0.013
CV_risk_obesity 407 (27.1%) 343 (26.9%) 64 (28.2%) 0.757
CV_risk_dyslipidemia 708 (47.2%) 598 (47.0%) 110 (48.5%) 0.734
CV_risk_Smoking 265 (17.7%) 222 (17.4%) 43 (18.9%) 0.651
history_med_MI 573 (38.2%) 491 (38.6%) 82 (36.1%) 0.532
history_coronary_procedure 1328 (88.5%) 1129 (88.7%) 199 (87.7%) 0.739
history_interv_PCI 105 (7.00%) 79 (6.21%) 26 (11.5%) 0.007
history_interv_CABG 1240 (82.7%) 1066 (83.7%) 174 (76.7%) 0.012
med_periph_atheroma 86 (5.73%) 58 (4.56%) 28 (12.3%) <0.001
history_stroke 50 (3.33%) 36 (2.83%) 14 (6.17%) 0.017
med_pacemaker 16 (1.07%) 16 (1.26%) 0 (0.00%) 0.152
med_CKD 34 (2.27%) 23 (1.81%) 11 (4.85%) 0.010
history_hospit_HF 95 (6.33%) 72 (5.66%) 23 (10.1%) 0.016
history_AFib 128 (8.53%) 95 (7.46%) 33 (14.5%) 0.001
clini_NYHA 198 (13.2%) 172 (13.5%) 26 (11.5%) 0.461
clini_cardiac_rythm 124 (8.27%) 95 (7.46%) 29 (12.8%) 0.011
CMR_LVEF_5 8.74 (1.17) 8.79 (1.16) 8.45 (1.21) <0.001
CMR_LVEDV_5 10.3 (2.21) 10.3 (2.17) 10.7 (2.43) 0.022
CMR_LVESV_5 5.89 (1.83) 5.83 (1.80) 6.24 (1.95) 0.004
CMR_LV_mass 90.3 (20.2) 89.9 (20.3) 92.3 (19.4) 0.090
CMR_RV_dysfunction 60 (4.00%) 33 (2.59%) 27 (11.9%) <0.001
CMR_LGE_ischemic_presence: <0.001
No_ischemic_LGE 703 (46.9%) 659 (51.8%) 44 (19.4%)
Presence_of_ischemic_LGE 797 (53.1%) 614 (48.2%) 183 (80.6%)
CMR_LGE_ischemic_extent_count 1.77 (2.11) 1.32 (1.64) 4.30 (2.63) <0.001
CMR_LGE_ischemic_extent_categ: <0.001
A_No_ischemic_LGE 703 (46.9%) 659 (51.8%) 44 (19.4%)
B_1_2_segments 284 (18.9%) 276 (21.7%) 8 (3.52%)
C_3_5_segments 418 (27.9%) 335 (26.3%) 83 (36.6%)
D_more6_segments 95 (6.33%) 3 (0.24%) 92 (40.5%)
CMR_LGE_ischemic_transmurality: <0.001
A_No_ischemic_LGE 703 (46.9%) 659 (51.8%) 44 (19.4%)
B_Subendocardial<50% 358 (23.9%) 332 (26.1%) 26 (11.5%)
C_Subendocardial≥50% 341 (22.7%) 257 (20.2%) 84 (37.0%)
D_Transmural 98 (6.53%) 25 (1.96%) 73 (32.2%)
CMR_LGE_ischemic_location_4: <0.001
A_No_ischemic_LGE 703 (46.9%) 659 (51.8%) 44 (19.4%)
B_Neither_anterior_nor_septal 535 (35.7%) 524 (41.2%) 11 (4.85%)
C_Anterior_without_septal 82 (5.47%) 60 (4.71%) 22 (9.69%)
D_Septal 180 (12.0%) 30 (2.36%) 150 (66.1%)
CMR_LGE_ischemic_anterior 222 (14.8%) 72 (5.66%) 150 (66.1%) <0.001
CMR_LGE_ischemic_septal 180 (12.0%) 30 (2.36%) 150 (66.1%) <0.001
CMR_LGE_ischemic_inferior 284 (18.9%) 257 (20.2%) 27 (11.9%) 0.004
CMR_LGE_ischemic_lateral 261 (17.4%) 189 (14.8%) 72 (31.7%) <0.001
CMR_LGE_ischemic_Apical 282 (18.8%) 182 (14.3%) 100 (44.1%) <0.001
CMR_LGE_midwall_presence: <0.001
A_No_midwall_LGE 1320 (88.0%) 1196 (94.0%) 124 (54.6%)
B_Presence_of_midwall_LGE 180 (12.0%) 77 (6.05%) 103 (45.4%)
CMR_LGE_presence_ischemic_and_midwall 115 (7.67%) 38 (2.99%) 77 (33.9%) <0.001
outcome_revascularisation_90days 596 (39.7%) 512 (40.2%) 84 (37.0%) 0.402
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab15-descr-MACEpop-death-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Tab16-descr-MACEpop-MACE

df_selected <- df_MACE %>%
  mutate(
    outcome_death = as.factor(outcome_death),
    outcome_MACE = as.factor(outcome_MACE),
    outcome_MACE_CV_death = as.factor(outcome_MACE_CV_death),
    outcome_MACE_NonFatal_MI = as.factor(outcome_MACE_NonFatal_MI),
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVEDV_5 = CMR_LVEDV/10,
    CMR_LVESV_5 = CMR_LVESV/10
  ) 

Descr_table = createTable(compareGroups(
      outcome_MACE ~ 
        outcome_death + outcome_MACE + outcome_MACE_CV_death + outcome_MACE_NonFatal_MI +
        demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
        CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
        
        history_med_MI  + history_coronary_procedure + history_interv_PCI + 
        history_interv_CABG + med_periph_atheroma + history_stroke + 
        med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
        clini_cardiac_rythm + 
        
        CMR_LVEF_5 + CMR_LVEDV_5 + 
        CMR_LVESV_5 + CMR_LV_mass + CMR_RV_dysfunction + 
        
        CMR_LGE_ischemic_presence + 
        CMR_LGE_ischemic_extent_count +
        CMR_LGE_ischemic_extent_categ + 
        CMR_LGE_ischemic_transmurality +
        CMR_LGE_ischemic_location_4 +
        
        CMR_LGE_ischemic_anterior + 
        CMR_LGE_ischemic_septal +
        CMR_LGE_ischemic_inferior +
        CMR_LGE_ischemic_lateral +
        CMR_LGE_ischemic_Apical +
        
        CMR_LGE_midwall_presence +
      
        CMR_LGE_presence_ischemic_and_midwall +
        
        outcome_revascularisation_90days,
  data= df_selected,
  method = 1, conf.level = 0.995), # Pvalue
  hide.no = "No", show.all = TRUE, show.p.overall = TRUE) # bug avec le hide

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `outcome_MACE’
[ALL] 0 1 p.overall
N=1500 N=1227 N=273
outcome_death: <0.001
0 1273 (84.9%) 1207 (98.4%) 66 (24.2%)
1 227 (15.1%) 20 (1.63%) 207 (75.8%)
outcome_MACE: 0.000
0 1227 (81.8%) 1227 (100%) 0 (0.00%)
1 273 (18.2%) 0 (0.00%) 273 (100%)
outcome_MACE_CV_death: <0.001
0 1286 (86.5%) 1213 (100%) 73 (26.7%)
1 200 (13.5%) 0 (0.00%) 200 (73.3%)
outcome_MACE_NonFatal_MI: <0.001
0 1414 (95.2%) 1213 (100%) 201 (73.6%)
1 72 (4.85%) 0 (0.00%) 72 (26.4%)
demo_age 64.2 (11.8) 63.3 (11.8) 68.1 (11.4) <0.001
demo_gender 1123 (74.9%) 892 (72.7%) 231 (84.6%) <0.001
demo_BMI 27.7 (5.47) 27.7 (5.58) 27.5 (4.95) 0.455
CV_risk_diabete 547 (36.5%) 410 (33.4%) 137 (50.2%) <0.001
CV_risk_HTA 650 (43.3%) 514 (41.9%) 136 (49.8%) 0.020
CV_risk_obesity 407 (27.1%) 336 (27.4%) 71 (26.0%) 0.698
CV_risk_dyslipidemia 708 (47.2%) 580 (47.3%) 128 (46.9%) 0.962
CV_risk_Smoking 265 (17.7%) 215 (17.5%) 50 (18.3%) 0.824
history_med_MI 573 (38.2%) 473 (38.5%) 100 (36.6%) 0.602
history_coronary_procedure 1328 (88.5%) 1087 (88.6%) 241 (88.3%) 0.967
history_interv_PCI 105 (7.00%) 79 (6.44%) 26 (9.52%) 0.094
history_interv_CABG 1240 (82.7%) 1024 (83.5%) 216 (79.1%) 0.105
med_periph_atheroma 86 (5.73%) 58 (4.73%) 28 (10.3%) 0.001
history_stroke 50 (3.33%) 35 (2.85%) 15 (5.49%) 0.044
med_pacemaker 16 (1.07%) 13 (1.06%) 3 (1.10%) 1.000
med_CKD 34 (2.27%) 23 (1.87%) 11 (4.03%) 0.053
history_hospit_HF 95 (6.33%) 71 (5.79%) 24 (8.79%) 0.088
history_AFib 128 (8.53%) 87 (7.09%) 41 (15.0%) <0.001
clini_NYHA 198 (13.2%) 162 (13.2%) 36 (13.2%) 1.000
clini_cardiac_rythm 124 (8.27%) 86 (7.01%) 38 (13.9%) <0.001
CMR_LVEF_5 8.74 (1.17) 8.78 (1.16) 8.53 (1.18) 0.001
CMR_LVEDV_5 10.3 (2.21) 10.3 (2.17) 10.6 (2.38) 0.038
CMR_LVESV_5 5.89 (1.83) 5.83 (1.81) 6.16 (1.92) 0.011
CMR_LV_mass 90.3 (20.2) 89.8 (20.2) 92.2 (20.1) 0.075
CMR_RV_dysfunction 60 (4.00%) 28 (2.28%) 32 (11.7%) <0.001
CMR_LGE_ischemic_presence: <0.001
No_ischemic_LGE 703 (46.9%) 634 (51.7%) 69 (25.3%)
Presence_of_ischemic_LGE 797 (53.1%) 593 (48.3%) 204 (74.7%)
CMR_LGE_ischemic_extent_count 1.77 (2.11) 1.31 (1.64) 3.86 (2.66) <0.001
CMR_LGE_ischemic_extent_categ: <0.001
A_No_ischemic_LGE 703 (46.9%) 634 (51.7%) 69 (25.3%)
B_1_2_segments 284 (18.9%) 275 (22.4%) 9 (3.30%)
C_3_5_segments 418 (27.9%) 307 (25.0%) 111 (40.7%)
D_more6_segments 95 (6.33%) 11 (0.90%) 84 (30.8%)
CMR_LGE_ischemic_transmurality: <0.001
A_No_ischemic_LGE 703 (46.9%) 634 (51.7%) 69 (25.3%)
B_Subendocardial<50% 358 (23.9%) 319 (26.0%) 39 (14.3%)
C_Subendocardial≥50% 341 (22.7%) 248 (20.2%) 93 (34.1%)
D_Transmural 98 (6.53%) 26 (2.12%) 72 (26.4%)
CMR_LGE_ischemic_location_4: <0.001
A_No_ischemic_LGE 703 (46.9%) 634 (51.7%) 69 (25.3%)
B_Neither_anterior_nor_septal 535 (35.7%) 503 (41.0%) 32 (11.7%)
C_Anterior_without_septal 82 (5.47%) 63 (5.13%) 19 (6.96%)
D_Septal 180 (12.0%) 27 (2.20%) 153 (56.0%)
CMR_LGE_ischemic_anterior 222 (14.8%) 72 (5.87%) 150 (54.9%) <0.001
CMR_LGE_ischemic_septal 180 (12.0%) 27 (2.20%) 153 (56.0%) <0.001
CMR_LGE_ischemic_inferior 284 (18.9%) 234 (19.1%) 50 (18.3%) 0.839
CMR_LGE_ischemic_lateral 261 (17.4%) 173 (14.1%) 88 (32.2%) <0.001
CMR_LGE_ischemic_Apical 282 (18.8%) 179 (14.6%) 103 (37.7%) <0.001
CMR_LGE_midwall_presence: <0.001
A_No_midwall_LGE 1320 (88.0%) 1141 (93.0%) 179 (65.6%)
B_Presence_of_midwall_LGE 180 (12.0%) 86 (7.01%) 94 (34.4%)
CMR_LGE_presence_ischemic_and_midwall 115 (7.67%) 43 (3.50%) 72 (26.4%) <0.001
outcome_revascularisation_90days 596 (39.7%) 490 (39.9%) 106 (38.8%) 0.787
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab16-descr-MACEpop-MACE-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Survival

Tab17-univ-MACEpop-death

df_selected <- df_MACE %>%
  mutate(
    surv.event = Surv(
      time = outcome_FU_time_death,
      event = outcome_death
    ),
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVEDV_5 = CMR_LVEDV/10,
    CMR_LVESV_5 = CMR_LVESV/10
  )

Descr_table = createTable(compareGroups(
      surv.event ~ 
        demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
        CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
        
        history_med_MI  + history_coronary_procedure + history_interv_PCI + 
        history_interv_CABG + med_periph_atheroma + history_stroke + 
        med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
        clini_cardiac_rythm + 
        
        CMR_LVEF_5 + CMR_LVEDV_5 + 
        CMR_LVESV_5 + CMR_LV_mass + CMR_RV_dysfunction + 
        
        CMR_LGE_ischemic_presence + 
        CMR_LGE_ischemic_extent_count +
        CMR_LGE_ischemic_extent_categ + 
        CMR_LGE_ischemic_transmurality +
        CMR_LGE_ischemic_location_4 +
        
        CMR_LGE_ischemic_anterior + 
        CMR_LGE_ischemic_septal +
        CMR_LGE_ischemic_inferior +
        CMR_LGE_ischemic_lateral +
        CMR_LGE_ischemic_Apical +
        
        CMR_LGE_midwall_presence +
      
        CMR_LGE_presence_ischemic_and_midwall +
        
        outcome_revascularisation_90days,
  data= df_selected,
  method = 1, conf.level = 0.995), # Pvalue
  hide.no = "No", show.p.ratio = T, show.ratio = TRUE) # bug avec le hide

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `surv.event’
No event Event HR p.ratio p.overall
N=1273 N=227
demo_age 63.3 (11.7) 69.1 (11.2) 1.04 [1.02;1.06] <0.001 <0.001
demo_gender 924 (72.6%) 199 (87.7%) 2.53 [1.43;4.46] <0.001 <0.001
demo_BMI 27.7 (5.52) 27.6 (5.20) 1.00 [0.97;1.04] 0.979 0.979
CV_risk_diabete 417 (32.8%) 130 (57.3%) 2.51 [1.72;3.65] <0.001 <0.001
CV_risk_HTA 534 (41.9%) 116 (51.1%) 1.41 [0.97;2.05] 0.010 0.010
CV_risk_obesity 343 (26.9%) 64 (28.2%) 1.08 [0.71;1.63] 0.610 0.605
CV_risk_dyslipidemia 598 (47.0%) 110 (48.5%) 1.16 [0.80;1.68] 0.274 0.273
CV_risk_Smoking 222 (17.4%) 43 (18.9%) 1.12 [0.69;1.80] 0.517 0.514
history_med_MI 491 (38.6%) 82 (36.1%) 0.94 [0.64;1.38] 0.649 0.647
history_coronary_procedure 1129 (88.7%) 199 (87.7%) 0.93 [0.53;1.63] 0.705 0.706
history_interv_PCI 79 (6.21%) 26 (11.5%) 1.78 [0.97;3.26] 0.008 0.007
history_interv_CABG 1066 (83.7%) 174 (76.7%) 0.69 [0.44;1.07] 0.018 0.018
med_periph_atheroma 58 (4.56%) 28 (12.3%) 2.81 [1.59;4.96] <0.001 <0.001
history_stroke 36 (2.83%) 14 (6.17%) 1.88 [0.85;4.17] 0.026 0.019
med_pacemaker 16 (1.26%) 0 (0.00%) 0.00 [0.00;.] 0.989 0.099
med_CKD 23 (1.81%) 11 (4.85%) 2.93 [1.23;6.99] 0.001 <0.001
history_hospit_HF 72 (5.66%) 23 (10.1%) 1.54 [0.83;2.85] 0.051 0.049
history_AFib 95 (7.46%) 33 (14.5%) 2.12 [1.25;3.60] <0.001 <0.001
clini_NYHA 172 (13.5%) 26 (11.5%) 0.76 [0.42;1.36] 0.179 0.178
clini_cardiac_rythm 95 (7.46%) 29 (12.8%) 1.90 [1.08;3.32] 0.001 0.001
CMR_LVEF_5 8.79 (1.16) 8.45 (1.21) 0.83 [0.72;0.95] <0.001 <0.001
CMR_LVEDV_5 10.3 (2.17) 10.7 (2.43) 1.07 [0.99;1.16] 0.012 0.012
CMR_LVESV_5 5.83 (1.80) 6.24 (1.95) 1.10 [1.01;1.20] 0.001 0.001
CMR_LV_mass 89.9 (20.3) 92.3 (19.4) 1.01 [1.00;1.02] 0.028 0.028
CMR_RV_dysfunction 33 (2.59%) 27 (11.9%) 3.84 [2.16;6.84] <0.001 <0.001
CMR_LGE_ischemic_presence: 0.000
No_ischemic_LGE 659 (51.8%) 44 (19.4%) Ref. Ref.
Presence_of_ischemic_LGE 614 (48.2%) 183 (80.6%) 3.84 [2.40;6.16] <0.001
CMR_LGE_ischemic_extent_count 1.32 (1.64) 4.30 (2.63) 1.61 [1.49;1.73] <0.001 <0.001
CMR_LGE_ischemic_extent_categ: 0.000
A_No_ischemic_LGE 659 (51.8%) 44 (19.4%) Ref. Ref.
B_1_2_segments 276 (21.7%) 8 (3.52%) 0.44 [0.15;1.30] 0.034
C_3_5_segments 335 (26.3%) 83 (36.6%) 3.35 [1.98;5.66] <0.001
D_more6_segments 3 (0.24%) 92 (40.5%) 20.6 [12.3;34.7] <0.001
CMR_LGE_ischemic_transmurality: 0.000
A_No_ischemic_LGE 659 (51.8%) 44 (19.4%) Ref. Ref.
B_Subendocardial<50% 332 (26.1%) 26 (11.5%) 1.23 [0.61;2.46] 0.409
C_Subendocardial≥50% 257 (20.2%) 84 (37.0%) 4.09 [2.43;6.91] <0.001
D_Transmural 25 (1.96%) 73 (32.2%) 12.4 [7.23;21.1] <0.001
CMR_LGE_ischemic_location_4: 0.000
A_No_ischemic_LGE 659 (51.8%) 44 (19.4%) Ref. Ref.
B_Neither_anterior_nor_septal 524 (41.2%) 11 (4.85%) 0.33 [0.13;0.85] 0.001
C_Anterior_without_septal 60 (4.71%) 22 (9.69%) 4.59 [2.21;9.56] <0.001
D_Septal 30 (2.36%) 150 (66.1%) 16.5 [10.2;26.8] <0.001
CMR_LGE_ischemic_anterior 72 (5.66%) 150 (66.1%) 14.2 [9.56;21.2] <0.001 0.000
CMR_LGE_ischemic_septal 30 (2.36%) 150 (66.1%) 17.7 [11.9;26.3] <0.001 0.000
CMR_LGE_ischemic_inferior 257 (20.2%) 27 (11.9%) 0.59 [0.33;1.05] 0.010 0.009
CMR_LGE_ischemic_lateral 189 (14.8%) 72 (31.7%) 2.29 [1.53;3.42] <0.001 <0.001
CMR_LGE_ischemic_Apical 182 (14.3%) 100 (44.1%) 3.80 [2.60;5.54] <0.001 0.000
CMR_LGE_midwall_presence: 0.000
A_No_midwall_LGE 1196 (94.0%) 124 (54.6%) Ref. Ref.
B_Presence_of_midwall_LGE 77 (6.05%) 103 (45.4%) 6.67 [4.58;9.72] <0.001
CMR_LGE_presence_ischemic_and_midwall 38 (2.99%) 77 (33.9%) 7.41 [4.98;11.0] <0.001 0.000
outcome_revascularisation_90days 512 (40.2%) 84 (37.0%) 0.94 [0.64;1.39] 0.678 0.679
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab17-univ-MACEpop-death-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Tab18-univ-MACEpop-MACE

df_selected <- df_MACE %>%
  mutate(
    surv.event = Surv(
      time = time.censored,
      event = outcome_MACE
    ),
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVEDV_5 = CMR_LVEDV/10,
    CMR_LVESV_5 = CMR_LVESV/10
  )

Descr_table = createTable(compareGroups(
      surv.event ~ 
        demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
        CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
        
        history_med_MI  + history_coronary_procedure + history_interv_PCI + 
        history_interv_CABG + med_periph_atheroma + history_stroke + 
        med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
        clini_cardiac_rythm + 
        
        CMR_LVEF_5 + CMR_LVEDV_5 + 
        CMR_LVESV_5 + CMR_LV_mass + CMR_RV_dysfunction + 
        
        CMR_LGE_ischemic_presence + 
        CMR_LGE_ischemic_extent_count +
        CMR_LGE_ischemic_extent_categ + 
        CMR_LGE_ischemic_transmurality +
        CMR_LGE_ischemic_location_4 +
        
        CMR_LGE_ischemic_anterior + 
        CMR_LGE_ischemic_septal +
        CMR_LGE_ischemic_inferior +
        CMR_LGE_ischemic_lateral +
        CMR_LGE_ischemic_Apical +
        
        CMR_LGE_midwall_presence +
      
        CMR_LGE_presence_ischemic_and_midwall +
        
        outcome_revascularisation_90days,
  data= df_selected,
  method = 1, conf.level = 0.995), # Pvalue
  hide.no = "No", show.p.ratio = T, show.ratio = TRUE) # bug avec le hide

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `surv.event’
No event Event HR p.ratio p.overall
N=1227 N=273
demo_age 63.3 (11.8) 68.1 (11.4) 1.03 [1.02;1.05] <0.001 <0.001
demo_gender 892 (72.7%) 231 (84.6%) 1.95 [1.22;3.12] <0.001 <0.001
demo_BMI 27.7 (5.58) 27.5 (4.95) 0.99 [0.96;1.03] 0.636 0.636
CV_risk_diabete 410 (33.4%) 137 (50.2%) 1.91 [1.36;2.68] <0.001 <0.001
CV_risk_HTA 514 (41.9%) 136 (49.8%) 1.34 [0.95;1.89] 0.015 0.015
CV_risk_obesity 336 (27.4%) 71 (26.0%) 0.96 [0.65;1.42] 0.790 0.789
CV_risk_dyslipidemia 580 (47.3%) 128 (46.9%) 1.07 [0.76;1.51] 0.555 0.553
CV_risk_Smoking 215 (17.5%) 50 (18.3%) 1.08 [0.69;1.67] 0.635 0.631
history_med_MI 473 (38.5%) 100 (36.6%) 0.96 [0.67;1.37] 0.741 0.741
history_coronary_procedure 1087 (88.6%) 241 (88.3%) 1.00 [0.59;1.69] 0.980 0.980
history_interv_PCI 79 (6.44%) 26 (9.52%) 1.42 [0.78;2.59] 0.101 0.100
history_interv_CABG 1024 (83.5%) 216 (79.1%) 0.80 [0.53;1.23] 0.149 0.148
med_periph_atheroma 58 (4.73%) 28 (10.3%) 2.22 [1.27;3.89] <0.001 <0.001
history_stroke 35 (2.85%) 15 (5.49%) 1.69 [0.79;3.62] 0.055 0.046
med_pacemaker 13 (1.06%) 3 (1.10%) 1.04 [0.20;5.31] 0.947 0.946
med_CKD 23 (1.87%) 11 (4.03%) 2.50 [1.05;5.93] 0.003 0.002
history_hospit_HF 71 (5.79%) 24 (8.79%) 1.34 [0.74;2.45] 0.168 0.168
history_AFib 87 (7.09%) 41 (15.0%) 2.27 [1.41;3.65] <0.001 <0.001
clini_NYHA 162 (13.2%) 36 (13.2%) 0.89 [0.54;1.47] 0.517 0.516
clini_cardiac_rythm 86 (7.01%) 38 (13.9%) 2.16 [1.32;3.53] <0.001 <0.001
CMR_LVEF_5 8.78 (1.16) 8.53 (1.18) 0.86 [0.75;0.98] 0.001 0.001
CMR_LVEDV_5 10.3 (2.17) 10.6 (2.38) 1.06 [0.98;1.14] 0.027 0.027
CMR_LVESV_5 5.83 (1.81) 6.16 (1.92) 1.08 [1.00;1.18] 0.006 0.006
CMR_LV_mass 89.8 (20.2) 92.2 (20.1) 1.01 [1.00;1.02] 0.020 0.020
CMR_RV_dysfunction 28 (2.28%) 32 (11.7%) 3.94 [2.32;6.69] <0.001 <0.001
CMR_LGE_ischemic_presence: <0.001
No_ischemic_LGE 634 (51.7%) 69 (25.3%) Ref. Ref.
Presence_of_ischemic_LGE 593 (48.3%) 204 (74.7%) 2.73 [1.85;4.03] <0.001
CMR_LGE_ischemic_extent_count 1.31 (1.64) 3.86 (2.66) 1.50 [1.40;1.61] <0.001 <0.001
CMR_LGE_ischemic_extent_categ: 0.000
A_No_ischemic_LGE 634 (51.7%) 69 (25.3%) Ref. Ref.
B_1_2_segments 275 (22.4%) 9 (3.30%) 0.31 [0.11;0.84] 0.001
C_3_5_segments 307 (25.0%) 111 (40.7%) 2.88 [1.87;4.43] <0.001
D_more6_segments 11 (0.90%) 84 (30.8%) 12.1 [7.65;19.1] <0.001
CMR_LGE_ischemic_transmurality: 0.000
A_No_ischemic_LGE 634 (51.7%) 69 (25.3%) Ref. Ref.
B_Subendocardial<50% 319 (26.0%) 39 (14.3%) 1.16 [0.66;2.04] 0.448
C_Subendocardial≥50% 248 (20.2%) 93 (34.1%) 2.90 [1.85;4.53] <0.001
D_Transmural 26 (2.12%) 72 (26.4%) 7.86 [4.89;12.6] <0.001
CMR_LGE_ischemic_location_4: 0.000
A_No_ischemic_LGE 634 (51.7%) 69 (25.3%) Ref. Ref.
B_Neither_anterior_nor_septal 503 (41.0%) 32 (11.7%) 0.61 [0.33;1.10] 0.019
C_Anterior_without_septal 63 (5.13%) 19 (6.96%) 2.50 [1.21;5.18] <0.001
D_Septal 27 (2.20%) 153 (56.0%) 10.9 [7.23;16.4] <0.001
CMR_LGE_ischemic_anterior 72 (5.87%) 150 (54.9%) 8.89 [6.30;12.5] <0.001 0.000
CMR_LGE_ischemic_septal 27 (2.20%) 153 (56.0%) 11.7 [8.32;16.6] <0.001 0.000
CMR_LGE_ischemic_inferior 234 (19.1%) 50 (18.3%) 0.99 [0.64;1.54] 0.953 0.954
CMR_LGE_ischemic_lateral 173 (14.1%) 88 (32.2%) 2.38 [1.65;3.43] <0.001 <0.001
CMR_LGE_ischemic_Apical 179 (14.6%) 103 (37.7%) 2.89 [2.04;4.11] <0.001 0.000
CMR_LGE_midwall_presence: 0.000
A_No_midwall_LGE 1141 (93.0%) 179 (65.6%) Ref. Ref.
B_Presence_of_midwall_LGE 86 (7.01%) 94 (34.4%) 4.28 [2.99;6.14] <0.001
CMR_LGE_presence_ischemic_and_midwall 43 (3.50%) 72 (26.4%) 5.33 [3.62;7.86] <0.001 0.000
outcome_revascularisation_90days 490 (39.9%) 106 (38.8%) 1.01 [0.71;1.43] 0.934 0.933
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab18-univ-MACEpop-MACE-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Tab19-multi_tradi-MACEpop-MACE

df <- df_MACE %>% mutate(
  event = outcome_MACE,
  time = time.censored
) %>% select(
  event, time,
  demo_age, demo_gender, demo_BMI , CV_risk_diabete , CV_risk_Smoking , CV_risk_dyslipidemia ,  history_hospit_HF, history_AFib, med_CKD, history_med_MI , CMR_LVEF, CMR_LGE_ischemic_presence) %>% droplevels()

#### TABLE 

## Model 1
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LVEF))

tbl_regression(model, exponentiate = FALSE, conf.level = 0.995,  pvalue_fun = function(x) style_pvalue(x, digits = 3), label = list()) %>% bold_p() %>% 
  as_gt() %>% gt::tab_header(gt::md("score coef - model 1"))
score coef - model 1
Characteristic log(HR)1 100% CI1 p-value
demo_age 0.03 0.01, 0.05 <0.001
demo_gender


    No — —
    Yes 0.67 0.19, 1.2 <0.001
demo_BMI -0.01 -0.05, 0.02 0.326
CV_risk_diabete


    No — —
    Yes 0.56 0.20, 0.93 <0.001
CV_risk_Smoking


    No — —
    Yes 0.23 -0.23, 0.68 0.163
CV_risk_dyslipidemia


    No — —
    Yes -0.03 -0.38, 0.32 0.835
history_hospit_HF


    No — —
    Yes -0.03 -0.65, 0.60 0.896
history_AFib


    No — —
    Yes 0.42 -0.08, 0.92 0.020
med_CKD


    No — —
    Yes 0.29 -0.60, 1.2 0.366
history_med_MI


    No — —
    Yes -0.09 -0.46, 0.27 0.475
CMR_LVEF -0.02 -0.04, 0.01 0.085
1 HR = Hazard Ratio, CI = Confidence Interval
## Model 2
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_presence))

tbl_regression(model, exponentiate = FALSE, conf.level = 0.995,  pvalue_fun = function(x) style_pvalue(x, digits = 3), label = list()) %>% bold_p() %>% 
  as_gt() %>% gt::tab_header(gt::md("score coef - model 2"))
score coef - model 2
Characteristic log(HR)1 100% CI1 p-value
demo_age 0.03 0.01, 0.05 <0.001
demo_gender


    No — —
    Yes 0.63 0.15, 1.1 <0.001
demo_BMI -0.01 -0.05, 0.02 0.351
CV_risk_diabete


    No — —
    Yes 0.48 0.11, 0.84 <0.001
CV_risk_Smoking


    No — —
    Yes 0.25 -0.21, 0.71 0.129
CV_risk_dyslipidemia


    No — —
    Yes 0.00 -0.35, 0.35 0.992
history_hospit_HF


    No — —
    Yes -0.03 -0.65, 0.60 0.911
history_AFib


    No — —
    Yes 0.40 -0.11, 0.90 0.028
med_CKD


    No — —
    Yes 0.25 -0.65, 1.1 0.438
history_med_MI


    No — —
    Yes -0.08 -0.44, 0.29 0.560
CMR_LVEF -0.01 -0.04, 0.02 0.348
CMR_LGE_ischemic_presence


    No_ischemic_LGE — —
    Presence_of_ischemic_LGE 0.91 0.51, 1.3 <0.001
1 HR = Hazard Ratio, CI = Confidence Interval
# Table uni multi 
table <- uni_multi_function(
  df = df, 
  event = "event",
  time = "time", 
  var_base = c("demo_age", "demo_gender" , "demo_BMI" , "CV_risk_diabete" , "CV_risk_Smoking" , "CV_risk_dyslipidemia" ,  "history_hospit_HF", "history_AFib" , "med_CKD" , "history_med_MI" , "CMR_LVEF"), 
  var_added = c("CMR_LGE_ischemic_presence"))

# export in html
knitr::kable(table, caption = "Model X - LGE presence - MACE population (N=1,500)", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model X - LGE presence - MACE population (N=1,500)
Variable Univariate_Analysis model_multi_1 model_multi_2
demo_age 1.03 (1.02-1.05), p=0.000 1.03 (1.01-1.05), p=0.000 1.03 (1.01-1.05), p=0.000
demo_genderYes 1.95 (1.22-3.12), p=0.000 1.96 (1.21-3.17), p=0.000 1.87 (1.16-3.03), p=0.000
demo_BMI 0.99 (0.96-1.03), p=0.636 0.99 (0.95-1.02), p=0.326 0.99 (0.95-1.02), p=0.351
CV_risk_diabeteYes 1.91 (1.36-2.68), p=0.000 1.76 (1.22-2.53), p=0.000 1.61 (1.12-2.33), p=0.000
CV_risk_SmokingYes 1.08 (0.69-1.67), p=0.635 1.25 (0.80-1.98), p=0.163 1.28 (0.81-2.03), p=0.129
CV_risk_dyslipidemiaYes 1.07 (0.76-1.51), p=0.555 0.97 (0.69-1.38), p=0.835 1.00 (0.71-1.42), p=0.992
history_hospit_HFYes 1.34 (0.74-2.45), p=0.168 0.97 (0.52-1.82), p=0.896 0.98 (0.52-1.83), p=0.911
history_AFibYes 2.27 (1.41-3.65), p=0.000 1.52 (0.92-2.51), p=0.020 1.49 (0.90-2.46), p=0.028
med_CKDYes 2.50 (1.05-5.93), p=0.003 1.33 (0.55-3.25), p=0.366 1.28 (0.52-3.12), p=0.438
history_med_MIYes 0.96 (0.67-1.37), p=0.741 0.91 (0.63-1.31), p=0.475 0.93 (0.64-1.33), p=0.560
CMR_LVEF 0.97 (0.95-1.00), p=0.001 0.98 (0.96-1.01), p=0.085 0.99 (0.96-1.02), p=0.348
CMR_LGE_ischemic_presencePresence_of_ischemic_LGE 2.73 (1.85-4.03), p=0.000 NA 2.47 (1.67-3.68), p=0.000
# Export in word
ft <- flextable(table)
ft <- set_table_properties(ft, layout = "autofit")
doc <- read_docx() %>%
  body_add_par("Model X - LGE presence in all pop (N=6,082)", style = "heading 1") %>%
  body_add_flextable(ft)

print(doc, target = here(tables_output_dir,paste0("Tab19-multi_tradi-MACEpop-MACE-",Sys.Date(), ".docx")))

MACE population + LGE (N=797)

Survival

Tab20-univ-MACE_LGEpop-death

df_selected <- df_MACE %>%
   filter(CMR_LGE_ischemic_presence == "Presence_of_ischemic_LGE") %>%
  mutate(
    surv.event = Surv(
      time = outcome_FU_time_death,
      event = outcome_death
    ),
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVEDV_5 = CMR_LVEDV/10,
    CMR_LVESV_5 = CMR_LVESV/10
  )

Descr_table = createTable(compareGroups(
      surv.event ~ 
        demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
        CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
        
        history_med_MI  + history_coronary_procedure + history_interv_PCI + 
        history_interv_CABG + med_periph_atheroma + history_stroke + 
        med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
        clini_cardiac_rythm + 
        
        CMR_LVEF_5 + CMR_LVEDV_5 + 
        CMR_LVESV_5 + CMR_LV_mass + CMR_RV_dysfunction + 
        
        CMR_LGE_ischemic_presence + 
        CMR_LGE_ischemic_extent_count +
        CMR_LGE_ischemic_extent_categ + 
        CMR_LGE_ischemic_transmurality +
        CMR_LGE_ischemic_location_4 +
        
        CMR_LGE_ischemic_anterior + 
        CMR_LGE_ischemic_septal +
        CMR_LGE_ischemic_inferior +
        CMR_LGE_ischemic_lateral +
        CMR_LGE_ischemic_Apical +
        
        CMR_LGE_midwall_presence +
      
        CMR_LGE_presence_ischemic_and_midwall +
        
        outcome_revascularisation_90days,
  data= df_selected,
  method = 1, conf.level = 0.995), # Pvalue
  hide.no = "No", show.p.ratio = T, show.ratio = TRUE) # bug avec le hide

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `surv.event’
No event Event HR p.ratio p.overall
N=614 N=183
demo_age 62.9 (11.3) 68.9 (11.1) 1.04 [1.02;1.06] <0.001 <0.001
demo_gender 458 (74.6%) 159 (86.9%) 2.11 [1.14;3.90] 0.001 <0.001
demo_BMI 27.9 (6.13) 27.7 (5.14) 1.00 [0.96;1.03] 0.786 0.786
CV_risk_diabete 222 (36.2%) 109 (59.6%) 2.28 [1.49;3.48] <0.001 <0.001
CV_risk_HTA 262 (42.7%) 95 (51.9%) 1.46 [0.96;2.22] 0.011 0.010
CV_risk_obesity 167 (27.2%) 53 (29.0%) 1.08 [0.68;1.71] 0.636 0.632
CV_risk_dyslipidemia 277 (45.1%) 96 (52.5%) 1.41 [0.93;2.15] 0.020 0.019
CV_risk_Smoking 111 (18.1%) 33 (18.0%) 1.01 [0.59;1.73] 0.966 0.959
history_med_MI 246 (40.1%) 63 (34.4%) 0.86 [0.55;1.33] 0.335 0.334
history_coronary_procedure 540 (87.9%) 162 (88.5%) 1.03 [0.54;1.98] 0.886 0.882
history_interv_PCI 40 (6.51%) 20 (10.9%) 1.66 [0.84;3.28] 0.038 0.036
history_interv_CABG 506 (82.4%) 142 (77.6%) 0.76 [0.46;1.25] 0.123 0.123
med_periph_atheroma 26 (4.23%) 24 (13.1%) 3.04 [1.64;5.66] <0.001 <0.001
history_stroke 22 (3.58%) 12 (6.56%) 1.76 [0.76;4.08] 0.058 0.055
med_pacemaker 8 (1.30%) 0 (0.00%) 0.00 [0.00;.] 0.994 0.137
med_CKD 11 (1.79%) 9 (4.92%) 2.48 [0.95;6.49] 0.008 0.006
history_hospit_HF 35 (5.70%) 21 (11.5%) 1.67 [0.87;3.21] 0.027 0.025
history_AFib 42 (6.84%) 27 (14.8%) 1.91 [1.07;3.44] 0.002 0.002
clini_NYHA 89 (14.5%) 23 (12.6%) 0.74 [0.39;1.38] 0.176 0.174
clini_cardiac_rythm 42 (6.84%) 26 (14.2%) 1.84 [1.01;3.33] 0.004 0.004
CMR_LVEF_5 8.72 (1.22) 8.40 (1.26) 0.87 [0.75;1.01] 0.010 0.010
CMR_LVEDV_5 10.4 (2.37) 10.7 (2.50) 1.03 [0.95;1.12] 0.323 0.323
CMR_LVESV_5 5.95 (1.97) 6.27 (2.02) 1.06 [0.96;1.17] 0.104 0.104
CMR_LV_mass 89.5 (20.9) 92.3 (19.4) 1.01 [1.00;1.02] 0.010 0.010
CMR_RV_dysfunction 20 (3.26%) 25 (13.7%) 3.51 [1.91;6.45] <0.001 <0.001
CMR_LGE_ischemic_presence: Presence_of_ischemic_LGE 614 (100%) 183 (100%) Ref. Ref. .
CMR_LGE_ischemic_extent_count 2.74 (1.29) 5.33 (1.75) 1.78 [1.60;1.97] <0.001 <0.001
CMR_LGE_ischemic_extent_categ: 0.000
B_1_2_segments 276 (45.0%) 8 (4.37%) Ref. Ref.
C_3_5_segments 335 (54.6%) 83 (45.4%) 7.64 [2.70;21.6] <0.001
D_more6_segments 3 (0.49%) 92 (50.3%) 46.5 [16.5;131] <0.001
CMR_LGE_ischemic_transmurality: 0.000
B_Subendocardial<50% 332 (54.1%) 26 (14.2%) Ref. Ref.
C_Subendocardial≥50% 257 (41.9%) 84 (45.9%) 3.37 [1.79;6.33] <0.001
D_Transmural 25 (4.07%) 73 (39.9%) 10.1 [5.29;19.1] <0.001
CMR_LGE_ischemic_location_4: 0.000
B_Neither_anterior_nor_septal 524 (85.3%) 11 (6.01%) Ref. Ref.
C_Anterior_without_septal 60 (9.77%) 22 (12.0%) 14.1 [4.98;39.6] <0.001
D_Septal 30 (4.89%) 150 (82.0%) 50.4 [21.0;121] <0.001
CMR_LGE_ischemic_anterior 72 (11.7%) 150 (82.0%) 15.1 [8.72;26.1] <0.001 0.000
CMR_LGE_ischemic_septal 30 (4.89%) 150 (82.0%) 19.2 [11.2;33.0] <0.001 0.000
CMR_LGE_ischemic_inferior 257 (41.9%) 27 (14.8%) 0.31 [0.17;0.55] <0.001 <0.001
CMR_LGE_ischemic_lateral 189 (30.8%) 72 (39.3%) 1.35 [0.88;2.08] 0.046 0.045
CMR_LGE_ischemic_Apical 182 (29.6%) 100 (54.6%) 2.43 [1.60;3.69] <0.001 <0.001
CMR_LGE_midwall_presence: 0.000
A_No_midwall_LGE 576 (93.8%) 106 (57.9%) Ref. Ref.
B_Presence_of_midwall_LGE 38 (6.19%) 77 (42.1%) 5.17 [3.39;7.89] <0.001
CMR_LGE_presence_ischemic_and_midwall 38 (6.19%) 77 (42.1%) 5.17 [3.39;7.89] <0.001 0.000
outcome_revascularisation_90days 512 (83.4%) 84 (45.9%) 0.30 [0.19;0.45] <0.001 0.000
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab20-univ-MACE_LGEpop-death-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Tab21-univ-MACE_LGEpop-MACE

df_selected <- df_MACE %>%
  filter(CMR_LGE_ischemic_presence == "Presence_of_ischemic_LGE") %>%
  mutate(
    surv.event = Surv(
      time = time.censored,
      event = outcome_MACE
    ),
    CMR_LVEF_5 = CMR_LVEF/5,
    CMR_LVEDV_5 = CMR_LVEDV/10,
    CMR_LVESV_5 = CMR_LVESV/10
  )

coxph(surv.event ~ med_pacemaker, data = df_selected)
## Call:
## coxph(formula = surv.event ~ med_pacemaker, data = df_selected)
## 
##                        coef  exp(coef)   se(coef)      z    p
## med_pacemakerYes -1.502e+01  3.003e-07  1.235e+03 -0.012 0.99
## 
## Likelihood ratio test=4.34  on 1 df, p=0.03728
## n= 797, number of events= 204
Descr_table = createTable(compareGroups(
      surv.event ~ 
        demo_age + demo_gender + demo_BMI + CV_risk_diabete + 
        CV_risk_HTA + CV_risk_obesity + CV_risk_dyslipidemia + CV_risk_Smoking + 
        
        history_med_MI  + history_coronary_procedure + history_interv_PCI + 
        history_interv_CABG + med_periph_atheroma + history_stroke + 
        med_pacemaker + med_CKD + history_hospit_HF + history_AFib + clini_NYHA + 
        clini_cardiac_rythm + 
        
        CMR_LVEF_5 + CMR_LVEDV_5 + 
        CMR_LVESV_5 + CMR_LV_mass + CMR_RV_dysfunction + 
        
        CMR_LGE_ischemic_presence + 
        CMR_LGE_ischemic_extent_count +
        CMR_LGE_ischemic_extent_categ + 
        CMR_LGE_ischemic_transmurality +
        CMR_LGE_ischemic_location_4 +
        
        CMR_LGE_ischemic_anterior + 
        CMR_LGE_ischemic_septal +
        CMR_LGE_ischemic_inferior +
        CMR_LGE_ischemic_lateral +
        CMR_LGE_ischemic_Apical +
        
        CMR_LGE_midwall_presence +
      
        CMR_LGE_presence_ischemic_and_midwall +
        
        outcome_revascularisation_90days,
  data= df_selected,
  method = 1, conf.level = 0.995), # Pvalue
  hide.no = "No", show.p.ratio = T, show.ratio = TRUE) # bug avec le hide

export2md(Descr_table, strip=TRUE, first.strip=TRUE)
Summary descriptives table by groups of `surv.event’
No event Event HR p.ratio p.overall
N=593 N=204
demo_age 62.7 (11.3) 68.9 (11.0) 1.04 [1.02;1.06] <0.001 <0.001
demo_gender 446 (75.2%) 171 (83.8%) 1.63 [0.96;2.78] 0.010 0.009
demo_BMI 28.0 (6.20) 27.5 (4.99) 0.99 [0.96;1.03] 0.496 0.496
CV_risk_diabete 223 (37.6%) 108 (52.9%) 1.74 [1.18;2.59] <0.001 <0.001
CV_risk_HTA 251 (42.3%) 106 (52.0%) 1.47 [0.99;2.18] 0.006 0.006
CV_risk_obesity 167 (28.2%) 53 (26.0%) 0.93 [0.59;1.46] 0.662 0.663
CV_risk_dyslipidemia 271 (45.7%) 102 (50.0%) 1.27 [0.85;1.88] 0.092 0.091
CV_risk_Smoking 109 (18.4%) 35 (17.2%) 0.96 [0.57;1.62] 0.843 0.849
history_med_MI 236 (39.8%) 73 (35.8%) 0.91 [0.60;1.37] 0.517 0.518
history_coronary_procedure 523 (88.2%) 179 (87.7%) 0.96 [0.53;1.75] 0.860 0.860
history_interv_PCI 41 (6.91%) 19 (9.31%) 1.35 [0.67;2.71] 0.223 0.222
history_interv_CABG 488 (82.3%) 160 (78.4%) 0.80 [0.50;1.30] 0.205 0.204
med_periph_atheroma 27 (4.55%) 23 (11.3%) 2.47 [1.32;4.62] <0.001 <0.001
history_stroke 21 (3.54%) 13 (6.37%) 1.70 [0.76;3.81] 0.064 0.061
med_pacemaker 8 (1.35%) 0 (0.00%) 0.00 [0.00;.] 0.990 0.139
med_CKD 12 (2.02%) 8 (3.92%) 1.95 [0.71;5.38] 0.064 0.060
history_hospit_HF 35 (5.90%) 21 (10.3%) 1.51 [0.79;2.88] 0.075 0.074
history_AFib 41 (6.91%) 28 (13.7%) 1.80 [1.02;3.20] 0.004 0.003
clini_NYHA 86 (14.5%) 26 (12.7%) 0.75 [0.42;1.36] 0.176 0.174
clini_cardiac_rythm 40 (6.75%) 28 (13.7%) 1.81 [1.02;3.21] 0.003 0.003
CMR_LVEF_5 8.71 (1.24) 8.47 (1.22) 0.91 [0.78;1.05] 0.060 0.060
CMR_LVEDV_5 10.4 (2.39) 10.7 (2.42) 1.03 [0.95;1.12] 0.278 0.278
CMR_LVESV_5 5.95 (2.00) 6.23 (1.95) 1.05 [0.95;1.15] 0.161 0.161
CMR_LV_mass 89.2 (20.7) 93.0 (20.2) 1.01 [1.00;1.02] 0.002 0.002
CMR_RV_dysfunction 17 (2.87%) 28 (13.7%) 3.72 [2.09;6.62] <0.001 <0.001
CMR_LGE_ischemic_presence: Presence_of_ischemic_LGE 593 (100%) 204 (100%) Ref. Ref. .
CMR_LGE_ischemic_extent_count 2.70 (1.33) 5.17 (1.65) 1.71 [1.56;1.88] <0.001 <0.001
CMR_LGE_ischemic_extent_categ: 0.000
B_1_2_segments 275 (46.4%) 9 (4.41%) Ref. Ref.
C_3_5_segments 307 (51.8%) 111 (54.4%) 9.33 [3.52;24.7] <0.001
D_more6_segments 11 (1.85%) 84 (41.2%) 39.0 [14.6;104] <0.001
CMR_LGE_ischemic_transmurality: 0.000
B_Subendocardial<50% 319 (53.8%) 39 (19.1%) Ref. Ref.
C_Subendocardial≥50% 248 (41.8%) 93 (45.6%) 2.50 [1.46;4.28] <0.001
D_Transmural 26 (4.38%) 72 (35.3%) 6.74 [3.85;11.8] <0.001
CMR_LGE_ischemic_location_4: 0.000
B_Neither_anterior_nor_septal 503 (84.8%) 32 (15.7%) Ref. Ref.
C_Anterior_without_septal 63 (10.6%) 19 (9.31%) 4.14 [1.84;9.35] <0.001
D_Septal 27 (4.55%) 153 (75.0%) 18.0 [10.4;31.2] <0.001
CMR_LGE_ischemic_anterior 72 (12.1%) 150 (73.5%) 9.21 [5.88;14.4] <0.001 0.000
CMR_LGE_ischemic_septal 27 (4.55%) 153 (75.0%) 12.9 [8.21;20.4] <0.001 0.000
CMR_LGE_ischemic_inferior 234 (39.5%) 50 (24.5%) 0.59 [0.37;0.93] 0.001 0.001
CMR_LGE_ischemic_lateral 173 (29.2%) 88 (43.1%) 1.62 [1.09;2.41] 0.001 0.001
CMR_LGE_ischemic_Apical 179 (30.2%) 103 (50.5%) 2.04 [1.37;3.02] <0.001 <0.001
CMR_LGE_midwall_presence: 0.000
A_No_midwall_LGE 550 (92.7%) 132 (64.7%) Ref. Ref.
B_Presence_of_midwall_LGE 43 (7.25%) 72 (35.3%) 4.01 [2.65;6.07] <0.001
CMR_LGE_presence_ischemic_and_midwall 43 (7.25%) 72 (35.3%) 4.01 [2.65;6.07] <0.001 0.000
outcome_revascularisation_90days 490 (82.6%) 106 (52.0%) 0.37 [0.25;0.55] <0.001 <0.001
export2word(x = Descr_table, 
            file = here(tables_output_dir, paste0("Tab21-univ-MACE_LGEpop-MACE-",Sys.Date(), ".docx")), 
            which.table="descr", nmax=TRUE, header.labels=c(), 
            caption=NULL, strip=FALSE, first.strip=FALSE, background="#D2D2D2",
            size=NULL, header.background=NULL, header.color=NULL)

Tab22-multi_tradi-MACE_LGEpop-MACE

df <- df_MACE %>% filter(CMR_LGE_ischemic_presence == "Presence_of_ischemic_LGE") %>%
  mutate(
  event = outcome_MACE,
  time = time.censored,
  CMR_LVEF_5 = CMR_LVEF/5,
  CMR_LGE_ischemic_transmurality_bin = case_when(
    CMR_LGE_ischemic_transmurality == "B_Subendocardial<50%" ~ "A_viable",
    CMR_LGE_ischemic_transmurality != "B_Subendocardial<50%" ~ "B_non_viable",
    TRUE ~ NA
  )
) %>% select(
  event, time,
  demo_age, demo_gender, demo_BMI , CV_risk_diabete , CV_risk_Smoking , CV_risk_dyslipidemia ,  history_hospit_HF, history_AFib, med_CKD, history_med_MI , CMR_LVEF_5, CMR_LGE_ischemic_extent_count, CMR_LGE_ischemic_transmurality_bin, CMR_LGE_ischemic_location_4, CMR_LGE_midwall_presence, outcome_revascularisation_90days) %>% droplevels()

#### TABLE 

## Model 1
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LVEF_5))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 1", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 1
Coefficients_CI HR_CI p_value
demo_age 0.04 ( 0.02 - 0.06 ) 1.04 ( 1.02 - 1.06 ) <0.001
demo_genderYes 0.51 ( -0.03 - 1.06 ) 1.67 ( 0.97 - 2.89 ) 0.008
demo_BMI -0.01 ( -0.05 - 0.03 ) 0.99 ( 0.95 - 1.03 ) 0.412
CV_risk_diabeteYes 0.47 ( 0.04 - 0.89 ) 1.59 ( 1.04 - 2.43 ) 0.002
CV_risk_SmokingYes 0.24 ( -0.31 - 0.79 ) 1.27 ( 0.73 - 2.20 ) 0.221
CV_risk_dyslipidemiaYes 0.16 ( -0.25 - 0.56 ) 1.17 ( 0.78 - 1.75 ) 0.277
history_hospit_HFYes 0.12 ( -0.56 - 0.80 ) 1.13 ( 0.57 - 2.23 ) 0.623
history_AFibYes 0.13 ( -0.48 - 0.73 ) 1.13 ( 0.62 - 2.08 ) 0.563
med_CKDYes 0.15 ( -0.90 - 1.19 ) 1.16 ( 0.41 - 3.30 ) 0.691
history_med_MIYes -0.09 ( -0.51 - 0.34 ) 0.92 ( 0.60 - 1.41 ) 0.574
CMR_LVEF_5 -0.03 ( -0.18 - 0.13 ) 0.97 ( 0.83 - 1.14 ) 0.646
write.csv(data, file = here("outputs", "csv_files","MACE_pop_model1_trad.csv"), append = FALSE)

## Model 2
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 2", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 2
Coefficients_CI HR_CI p_value
demo_age 0.02 ( -0.00 - 0.04 ) 1.02 ( 1.00 - 1.04 ) 0.005
demo_genderYes 0.30 ( -0.25 - 0.86 ) 1.35 ( 0.78 - 2.35 ) 0.127
demo_BMI -0.01 ( -0.05 - 0.04 ) 0.99 ( 0.95 - 1.04 ) 0.664
CV_risk_diabeteYes 0.25 ( -0.17 - 0.67 ) 1.28 ( 0.84 - 1.95 ) 0.096
CV_risk_SmokingYes 0.22 ( -0.34 - 0.78 ) 1.24 ( 0.71 - 2.17 ) 0.280
CV_risk_dyslipidemiaYes 0.14 ( -0.28 - 0.55 ) 1.14 ( 0.75 - 1.74 ) 0.366
history_hospit_HFYes 0.01 ( -0.71 - 0.73 ) 1.01 ( 0.49 - 2.08 ) 0.969
history_AFibYes -0.04 ( -0.68 - 0.60 ) 0.96 ( 0.51 - 1.83 ) 0.864
med_CKDYes 0.42 ( -0.69 - 1.53 ) 1.52 ( 0.50 - 4.60 ) 0.290
history_med_MIYes 0.23 ( -0.21 - 0.67 ) 1.26 ( 0.81 - 1.96 ) 0.147
CMR_LVEF_5 0.02 ( -0.15 - 0.20 ) 1.02 ( 0.86 - 1.22 ) 0.700
CMR_LGE_ischemic_extent_count 0.50 ( 0.40 - 0.61 ) 1.66 ( 1.49 - 1.83 ) <0.001
## Model 3A
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_transmurality_bin))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 3A", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 3A
Coefficients_CI HR_CI p_value
demo_age 0.02 ( -0.00 - 0.04 ) 1.02 ( 1.00 - 1.04 ) 0.014
demo_genderYes 0.30 ( -0.26 - 0.86 ) 1.35 ( 0.77 - 2.35 ) 0.130
demo_BMI -0.01 ( -0.05 - 0.03 ) 0.99 ( 0.95 - 1.03 ) 0.566
CV_risk_diabeteYes 0.24 ( -0.18 - 0.66 ) 1.27 ( 0.83 - 1.94 ) 0.110
CV_risk_SmokingYes 0.18 ( -0.38 - 0.73 ) 1.19 ( 0.68 - 2.09 ) 0.372
CV_risk_dyslipidemiaYes 0.16 ( -0.26 - 0.58 ) 1.17 ( 0.77 - 1.78 ) 0.297
history_hospit_HFYes -0.06 ( -0.78 - 0.67 ) 0.95 ( 0.46 - 1.95 ) 0.829
history_AFibYes -0.09 ( -0.73 - 0.56 ) 0.92 ( 0.48 - 1.75 ) 0.709
med_CKDYes 0.40 ( -0.71 - 1.50 ) 1.49 ( 0.49 - 4.50 ) 0.316
history_med_MIYes 0.31 ( -0.14 - 0.76 ) 1.37 ( 0.87 - 2.14 ) 0.051
CMR_LVEF_5 0.03 ( -0.15 - 0.20 ) 1.03 ( 0.86 - 1.23 ) 0.661
CMR_LGE_ischemic_extent_count 0.48 ( 0.37 - 0.58 ) 1.61 ( 1.45 - 1.79 ) <0.001
CMR_LGE_ischemic_transmurality_binB_non_viable 0.79 ( 0.27 - 1.31 ) 2.21 ( 1.32 - 3.71 ) <0.001
## Model 3B
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count, CMR_LGE_ischemic_location_4))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 3B", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 3B
Coefficients_CI HR_CI p_value
demo_age 0.02 ( -0.00 - 0.04 ) 1.02 ( 1.00 - 1.04 ) 0.012
demo_genderYes 0.12 ( -0.45 - 0.68 ) 1.13 ( 0.64 - 1.98 ) 0.553
demo_BMI -0.00 ( -0.05 - 0.04 ) 1.00 ( 0.96 - 1.04 ) 0.909
CV_risk_diabeteYes 0.16 ( -0.26 - 0.58 ) 1.18 ( 0.77 - 1.79 ) 0.273
CV_risk_SmokingYes 0.20 ( -0.37 - 0.76 ) 1.22 ( 0.69 - 2.14 ) 0.332
CV_risk_dyslipidemiaYes 0.17 ( -0.25 - 0.60 ) 1.19 ( 0.78 - 1.82 ) 0.259
history_hospit_HFYes 0.06 ( -0.68 - 0.80 ) 1.06 ( 0.51 - 2.23 ) 0.814
history_AFibYes -0.03 ( -0.67 - 0.62 ) 0.97 ( 0.51 - 1.86 ) 0.908
med_CKDYes -0.08 ( -1.21 - 1.04 ) 0.92 ( 0.30 - 2.82 ) 0.833
history_med_MIYes 0.21 ( -0.23 - 0.66 ) 1.24 ( 0.79 - 1.93 ) 0.178
CMR_LVEF_5 0.12 ( -0.07 - 0.31 ) 1.13 ( 0.93 - 1.36 ) 0.077
CMR_LGE_ischemic_extent_count 0.22 ( 0.10 - 0.34 ) 1.25 ( 1.10 - 1.41 ) <0.001
CMR_LGE_ischemic_location_4C_Anterior_without_septal 1.15 ( 0.31 - 1.99 ) 3.17 ( 1.37 - 7.32 ) <0.001
CMR_LGE_ischemic_location_4D_Septal 2.29 ( 1.65 - 2.93 ) 9.88 ( 5.19 - 18.80 ) <0.001
## Model 3C
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event:CMR_LGE_ischemic_extent_count, CMR_LGE_midwall_presence))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 3C", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 3C
Coefficients_CI HR_CI p_value
demo_age 0.02 ( -0.01 - 0.04 ) 1.02 ( 0.99 - 1.04 ) 0.042
demo_genderYes 0.42 ( -0.14 - 0.99 ) 1.53 ( 0.87 - 2.69 ) 0.034
demo_BMI -0.01 ( -0.06 - 0.03 ) 0.99 ( 0.95 - 1.03 ) 0.395
CV_risk_diabeteYes 0.28 ( -0.14 - 0.70 ) 1.33 ( 0.87 - 2.02 ) 0.057
CV_risk_SmokingYes 0.21 ( -0.35 - 0.77 ) 1.24 ( 0.70 - 2.17 ) 0.289
CV_risk_dyslipidemiaYes 0.16 ( -0.26 - 0.57 ) 1.17 ( 0.77 - 1.78 ) 0.285
history_hospit_HFYes 0.05 ( -0.67 - 0.77 ) 1.05 ( 0.51 - 2.16 ) 0.841
history_AFibYes 0.01 ( -0.63 - 0.64 ) 1.01 ( 0.53 - 1.90 ) 0.982
med_CKDYes 0.41 ( -0.68 - 1.50 ) 1.51 ( 0.51 - 4.48 ) 0.290
history_med_MIYes 0.15 ( -0.30 - 0.60 ) 1.16 ( 0.74 - 1.81 ) 0.355
CMR_LVEF_5 0.07 ( -0.11 - 0.25 ) 1.07 ( 0.90 - 1.28 ) 0.288
CMR_LGE_ischemic_extent_count 0.47 ( 0.36 - 0.57 ) 1.60 ( 1.44 - 1.77 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.74 ( 0.29 - 1.20 ) 2.10 ( 1.34 - 3.30 ) <0.001
## Model 4
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event: CMR_LGE_midwall_presence))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 4", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 4
Coefficients_CI HR_CI p_value
demo_age 0.01 ( -0.01 - 0.04 ) 1.01 ( 0.99 - 1.04 ) 0.064
demo_genderYes 0.12 ( -0.45 - 0.69 ) 1.13 ( 0.64 - 1.99 ) 0.558
demo_BMI -0.01 ( -0.05 - 0.03 ) 0.99 ( 0.95 - 1.03 ) 0.499
CV_risk_diabeteYes 0.17 ( -0.25 - 0.59 ) 1.19 ( 0.78 - 1.81 ) 0.246
CV_risk_SmokingYes 0.21 ( -0.35 - 0.78 ) 1.24 ( 0.70 - 2.18 ) 0.295
CV_risk_dyslipidemiaYes 0.27 ( -0.16 - 0.70 ) 1.31 ( 0.85 - 2.02 ) 0.075
history_hospit_HFYes 0.12 ( -0.62 - 0.87 ) 1.13 ( 0.54 - 2.38 ) 0.639
history_AFibYes 0.03 ( -0.61 - 0.67 ) 1.03 ( 0.54 - 1.96 ) 0.891
med_CKDYes 0.00 ( -1.11 - 1.12 ) 1.00 ( 0.33 - 3.06 ) 0.990
history_med_MIYes 0.16 ( -0.29 - 0.61 ) 1.18 ( 0.75 - 1.85 ) 0.317
CMR_LVEF_5 0.16 ( -0.03 - 0.34 ) 1.17 ( 0.97 - 1.41 ) 0.020
CMR_LGE_ischemic_extent_count 0.22 ( 0.09 - 0.34 ) 1.24 ( 1.10 - 1.40 ) <0.001
CMR_LGE_ischemic_transmurality_binB_non_viable 0.38 ( -0.15 - 0.92 ) 1.47 ( 0.86 - 2.51 ) 0.045
CMR_LGE_ischemic_location_4C_Anterior_without_septal 0.90 ( 0.03 - 1.78 ) 2.46 ( 1.03 - 5.92 ) 0.004
CMR_LGE_ischemic_location_4D_Septal 2.09 ( 1.43 - 2.75 ) 8.07 ( 4.17 - 15.62 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.65 ( 0.20 - 1.10 ) 1.91 ( 1.22 - 3.00 ) <0.001
write.csv(data, file = here("outputs", "csv_files","MACE_pop_model4_trad.csv"), append = FALSE)

## Model 5
model <- coxph(formula =  Surv(time, event) ~ ., data = df %>% select(event: outcome_revascularisation_90days))
data <- extract_model_stats(model, conf_level = 0.995)
knitr::kable(data, caption = "Model 4", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model 4
Coefficients_CI HR_CI p_value
demo_age 0.02 ( -0.00 - 0.05 ) 1.02 ( 1.00 - 1.05 ) 0.007
demo_genderYes 0.17 ( -0.41 - 0.74 ) 1.18 ( 0.67 - 2.10 ) 0.412
demo_BMI -0.01 ( -0.06 - 0.03 ) 0.99 ( 0.95 - 1.03 ) 0.414
CV_risk_diabeteYes 0.19 ( -0.23 - 0.61 ) 1.21 ( 0.80 - 1.85 ) 0.193
CV_risk_SmokingYes 0.24 ( -0.33 - 0.81 ) 1.27 ( 0.72 - 2.24 ) 0.243
CV_risk_dyslipidemiaYes 0.29 ( -0.14 - 0.72 ) 1.34 ( 0.87 - 2.05 ) 0.057
history_hospit_HFYes 0.12 ( -0.61 - 0.86 ) 1.13 ( 0.54 - 2.37 ) 0.636
history_AFibYes 0.00 ( -0.64 - 0.64 ) 1.00 ( 0.53 - 1.90 ) 0.991
med_CKDYes 0.06 ( -1.05 - 1.17 ) 1.06 ( 0.35 - 3.23 ) 0.880
history_med_MIYes 0.20 ( -0.25 - 0.66 ) 1.23 ( 0.78 - 1.93 ) 0.205
CMR_LVEF_5 0.18 ( -0.01 - 0.37 ) 1.20 ( 0.99 - 1.45 ) 0.007
CMR_LGE_ischemic_extent_count 0.24 ( 0.11 - 0.36 ) 1.27 ( 1.12 - 1.43 ) <0.001
CMR_LGE_ischemic_transmurality_binB_non_viable 0.49 ( -0.05 - 1.03 ) 1.63 ( 0.95 - 2.80 ) 0.012
CMR_LGE_ischemic_location_4C_Anterior_without_septal 0.84 ( -0.05 - 1.72 ) 2.31 ( 0.95 - 5.60 ) 0.008
CMR_LGE_ischemic_location_4D_Septal 2.18 ( 1.51 - 2.84 ) 8.82 ( 4.54 - 17.14 ) <0.001
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.71 ( 0.26 - 1.16 ) 2.03 ( 1.29 - 3.20 ) <0.001
outcome_revascularisation_90daysYes 0.48 ( -0.00 - 0.96 ) 1.62 ( 1.00 - 2.62 ) 0.005
## MODELS MULTI NESTED
var_base = c("demo_age", "demo_gender" , "demo_BMI" , "CV_risk_diabete" , "CV_risk_Smoking" , "CV_risk_dyslipidemia" ,  "history_hospit_HF", "history_AFib" , "med_CKD" , "history_med_MI" , "CMR_LVEF_5")

### Nested 4
table <- uni_multi_function(
  df = df, 
  event = "event",
  time = "time", 
  var_base = var_base, 
  var_added = c("CMR_LGE_ischemic_extent_count", "CMR_LGE_ischemic_transmurality_bin","CMR_LGE_ischemic_location_4",
                "CMR_LGE_midwall_presence", "outcome_revascularisation_90days"))

# export in html
knitr::kable(table, caption = "Model full - MACE granularity (MACE = 797)", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Model full - MACE granularity (MACE = 797)
Variable Univariate_Analysis model_multi_1 model_multi_2 model_multi_3 model_multi_4 model_multi_5 model_multi_6
demo_age 1.04 (1.02-1.06), p=0.000 1.04 (1.02-1.06), p=0.000 1.02 (1.00-1.04), p=0.005 1.02 (1.00-1.04), p=0.014 1.02 (1.00-1.04), p=0.016 1.01 (0.99-1.04), p=0.064 1.02 (1.00-1.05), p=0.007
demo_genderYes 1.63 (0.96-2.78), p=0.010 1.67 (0.97-2.89), p=0.008 1.35 (0.78-2.35), p=0.127 1.35 (0.77-2.35), p=0.130 1.15 (0.65-2.02), p=0.495 1.13 (0.64-1.99), p=0.558 1.18 (0.67-2.10), p=0.412
demo_BMI 0.99 (0.96-1.03), p=0.496 0.99 (0.95-1.03), p=0.412 0.99 (0.95-1.04), p=0.664 0.99 (0.95-1.03), p=0.566 1.00 (0.95-1.04), p=0.784 0.99 (0.95-1.03), p=0.499 0.99 (0.95-1.03), p=0.414
CV_risk_diabeteYes 1.74 (1.18-2.59), p=0.000 1.59 (1.04-2.43), p=0.002 1.28 (0.84-1.95), p=0.096 1.27 (0.83-1.94), p=0.110 1.17 (0.77-1.79), p=0.290 1.19 (0.78-1.81), p=0.246 1.21 (0.80-1.85), p=0.193
CV_risk_SmokingYes 0.96 (0.57-1.62), p=0.843 1.27 (0.73-2.20), p=0.221 1.24 (0.71-2.17), p=0.280 1.19 (0.68-2.09), p=0.372 1.23 (0.70-2.15), p=0.310 1.24 (0.70-2.18), p=0.295 1.27 (0.72-2.24), p=0.243
CV_risk_dyslipidemiaYes 1.27 (0.85-1.88), p=0.092 1.17 (0.78-1.75), p=0.277 1.14 (0.75-1.74), p=0.366 1.17 (0.77-1.78), p=0.297 1.24 (0.81-1.91), p=0.159 1.31 (0.85-2.02), p=0.075 1.34 (0.87-2.05), p=0.057
history_hospit_HFYes 1.51 (0.79-2.88), p=0.075 1.13 (0.57-2.23), p=0.623 1.01 (0.49-2.08), p=0.969 0.95 (0.46-1.95), p=0.829 1.03 (0.49-2.16), p=0.922 1.13 (0.54-2.38), p=0.639 1.13 (0.54-2.37), p=0.636
history_AFibYes 1.80 (1.02-3.20), p=0.004 1.13 (0.62-2.08), p=0.563 0.96 (0.51-1.83), p=0.864 0.92 (0.48-1.75), p=0.709 0.98 (0.51-1.87), p=0.931 1.03 (0.54-1.96), p=0.891 1.00 (0.53-1.90), p=0.991
med_CKDYes 1.95 (0.71-5.38), p=0.064 1.16 (0.41-3.30), p=0.691 1.52 (0.50-4.60), p=0.290 1.49 (0.49-4.50), p=0.316 0.96 (0.31-2.95), p=0.920 1.00 (0.33-3.06), p=0.990 1.06 (0.35-3.23), p=0.880
history_med_MIYes 0.91 (0.60-1.37), p=0.517 0.92 (0.60-1.41), p=0.574 1.26 (0.81-1.96), p=0.147 1.37 (0.87-2.14), p=0.051 1.31 (0.84-2.06), p=0.089 1.18 (0.75-1.85), p=0.317 1.23 (0.78-1.93), p=0.205
CMR_LVEF_5 0.91 (0.78-1.05), p=0.060 0.97 (0.83-1.14), p=0.646 1.02 (0.86-1.22), p=0.700 1.03 (0.86-1.23), p=0.661 1.13 (0.94-1.37), p=0.063 1.17 (0.97-1.41), p=0.020 1.20 (0.99-1.45), p=0.007
CMR_LGE_ischemic_extent_count 1.71 (1.56-1.88), p=0.000 NA 1.66 (1.49-1.83), p=0.000 1.61 (1.45-1.79), p=0.000 1.25 (1.10-1.41), p=0.000 1.24 (1.10-1.40), p=0.000 1.27 (1.12-1.43), p=0.000
CMR_LGE_ischemic_transmurality_binB_non_viable 3.46 (2.10-5.70), p=0.000 NA NA 2.21 (1.32-3.71), p=0.000 1.55 (0.91-2.64), p=0.022 1.47 (0.86-2.51), p=0.045 1.63 (0.95-2.80), p=0.012
CMR_LGE_ischemic_location_4C_Anterior_without_septal 4.14 (1.84-9.35), p=0.000 NA NA NA 3.10 (1.34-7.17), p=0.000 2.46 (1.03-5.92), p=0.004 2.31 (0.95-5.60), p=0.008
CMR_LGE_ischemic_location_4D_Septal 18.04 (10.44-31.16), p=0.000 NA NA NA 8.81 (4.58-16.98), p=0.000 8.07 (4.17-15.62), p=0.000 8.82 (4.54-17.14), p=0.000
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 4.01 (2.65-6.07), p=0.000 NA NA NA NA 1.91 (1.22-3.00), p=0.000 2.03 (1.29-3.20), p=0.000
outcome_revascularisation_90daysYes 0.37 (0.25-0.55), p=0.000 NA NA NA NA NA 1.62 (1.00-2.62), p=0.005
# Export in word
ft <- flextable(table)
ft <- set_table_properties(ft, layout = "autofit")
doc <- read_docx() %>%
  body_add_par("Model 4 - MACE with LGE pop (794)", style = "heading 1") %>%
  body_add_flextable(ft)
print(doc, target = here(tables_output_dir,paste0("Tab22-multi_tradi-MACE_LGEpop-MACE-",Sys.Date(), ".docx")))

Tab23-incr-MACE_LGEpop-MACE

var1 <- c("demo_age", "demo_gender" , "demo_BMI" , "CV_risk_diabete" , "CV_risk_Smoking" , "CV_risk_dyslipidemia" ,  "history_hospit_HF", "history_AFib" , "med_CKD" , "history_med_MI" , "CMR_LVEF_5")
var2 <- c(var1, "CMR_LGE_ischemic_extent_count")
var3A <- c(var2, "CMR_LGE_ischemic_transmurality_bin")
var3B <- c(var2, "CMR_LGE_ischemic_location_4")
var3C <-  c(var2, "CMR_LGE_midwall_presence")
var4 <- c(var2, "CMR_LGE_ischemic_transmurality_bin", "CMR_LGE_ischemic_location_4", "CMR_LGE_midwall_presence")

df_selected <- df_MACE %>% filter(
  CMR_LGE_ischemic_presence=="Presence_of_ischemic_LGE") %>% mutate(
  time = time.censored,
  event = outcome_MACE,
  CMR_LVEF_5 = CMR_LVEF/5,
  CMR_LGE_ischemic_transmurality_bin = case_when(
    CMR_LGE_ischemic_transmurality == "B_Subendocardial<50%" ~ "A_viable",
    CMR_LGE_ischemic_transmurality != "B_Subendocardial<50%" ~ "B_non_viable",
    TRUE ~ NA)
) %>% droplevels()


# MODEL 1
results.model1 <- CoxPredictScore(derivation = df_selected, validation = df_selected,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var1, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model1$model_stats
## NULL
results.model1$derivation$auc
## [1] "0.66 [0.6-0.72]"
# MODEL 2
results.model2 <- CoxPredictScore(derivation = df_selected, validation = df_selected,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var2, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model2$model_stats
## NULL
results.model2$derivation$auc
## [1] "0.83 [0.77-0.86]"
roc.test(results.model1$roc_derivation$roc_obj, results.model2$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model1$roc_derivation$roc_obj and results.model2$roc_derivation$roc_obj
## Z = -6.4573, p-value = 1.066e-10
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.2116426 -0.1130805
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.6644607   0.8268223
# MODEL 3A
results.model3A <- CoxPredictScore(derivation = df_selected, validation = df_selected,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3A, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3A$model_stats
## NULL
results.model3A$derivation$auc
## [1] "0.83 [0.78-0.87]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3A$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3A$roc_derivation$roc_obj
## Z = -0.32169, p-value = 0.7477
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.01749672  0.01256302
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8268223   0.8292891
# MODEL 3B
results.model3B <- CoxPredictScore(derivation = df_selected, validation = df_selected,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3B, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3B$model_stats
## NULL
results.model3B$derivation$auc
## [1] "0.86 [0.82-0.91]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3B$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3B$roc_derivation$roc_obj
## Z = -2.5217, p-value = 0.01168
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.066648317 -0.008353462
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8268223   0.8643232
# MODEL 3C
results.model3C <- CoxPredictScore(derivation = df_selected, validation = df_selected,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var3C, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model3C$model_stats
## NULL
results.model3C$derivation$auc
## [1] "0.84 [0.8-0.88]"
roc.test(results.model2$roc_derivation$roc_obj, results.model3C$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model3C$roc_derivation$roc_obj
## Z = -2.1886, p-value = 0.02862
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.03111324 -0.00171486
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8268223   0.8432363
# MODEL 4
results.model4 <- CoxPredictScore(derivation = df_selected, validation = df_selected,
                       time.name = "time", 
                       times = 10*12,
                       event.name ="event", 
                       variables = var4, 
                       n_bootstrap = 100, 
                       ci_level = 0.995, 
                       seed = 123)

results.model4$model_stats
## NULL
results.model4$derivation$auc
## [1] "0.87 [0.83-0.91]"
roc.test(results.model2$roc_derivation$roc_obj, results.model4$roc_derivation$roc_obj)
## 
##  DeLong's test for two correlated ROC curves
## 
## data:  results.model2$roc_derivation$roc_obj and results.model4$roc_derivation$roc_obj
## Z = -2.6925, p-value = 0.007091
## alternative hypothesis: true difference in AUC is not equal to 0
## 95 percent confidence interval:
##  -0.07475831 -0.01177126
## sample estimates:
## AUC of roc1 AUC of roc2 
##   0.8268223   0.8700871

Score using all LGE population

Tab24-score_development

# 1) Coxph function
df <- df_LGE %>% droplevels()

# Function

# Assuming model is already correctly fitted as shown:
model <- coxph(formula =  Surv(outcome_FU_time_death, outcome_death) ~ CMR_LGE_ischemic_extent_count + CMR_LGE_ischemic_transmurality + CMR_LGE_ischemic_location_4 + CMR_LGE_midwall_presence, data = df)



# Function
data <- extract_model_stats(model, conf_level = 0.995, decimals = 2)

# Additional transformations as per your code (multiplying coefficients by 3, etc.)
data <- data %>%
  mutate(
    # Extract the coefficient and convert to numeric using gsub to remove non-numeric parts
    coefficients = as.numeric(gsub(" .*", "", Coefficients_CI)),
    # Multiply the extracted coefficient by 3
    coeff_x3 = coefficients * 3,
    # Round the result of the multiplication
    score = round(coeff_x3)
  )


knitr::kable(data, caption = "Score", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Score
Coefficients_CI HR_CI p_value coefficients coeff_x3 score
CMR_LGE_ischemic_extent_count 0.32 ( 0.25 - 0.39 ) 1.38 ( 1.28 - 1.48 ) <0.001 0.32 0.96 1
CMR_LGE_ischemic_transmuralityC_Subendocardial≥50% 0.82 ( 0.45 - 1.19 ) 2.28 ( 1.58 - 3.28 ) <0.001 0.82 2.46 2
CMR_LGE_ischemic_transmuralityD_Transmural 1.15 ( 0.75 - 1.55 ) 3.16 ( 2.12 - 4.73 ) <0.001 1.15 3.45 3
CMR_LGE_ischemic_location_4C_Anterior_without_septal 1.60 ( 1.20 - 2.00 ) 4.95 ( 3.31 - 7.41 ) <0.001 1.60 4.80 5
CMR_LGE_ischemic_location_4D_Septal 2.06 ( 1.70 - 2.43 ) 7.87 ( 5.45 - 11.35 ) <0.001 2.06 6.18 6
CMR_LGE_midwall_presenceB_Presence_of_midwall_LGE 0.63 ( 0.35 - 0.92 ) 1.88 ( 1.41 - 2.51 ) <0.001 0.63 1.89 2
# Create a new Word document
write.csv(x = data, file = here(tables_output_dir,"Tab24-score_development.csv"), col.names = TRUE)


# 3) Find best cut-off
fit = partykit::ctree(Surv(outcome_FU_time_death/12, outcome_death) ~ score, data = df, maxdepth = 2)

plot(fit,
     main = "Decision tree for score on derivation (N=2,900)",
     digits = 2, cex = 0.2, branch.type = "square",
     tp_args = list(pval = TRUE), 
     gp_args = list(fontsize = 2))

## Fig14-Schoenfelds_residuals_score

fit <- coxph(formula =  Surv(outcome_FU_time_death, outcome_death) ~ score, data = df_LGE)

model <- cox.zph(fit)

plot <- ggcoxzph(model)[1]
plot
## $`1`

    # Save each plot
ggsave(
    filename = here(figures_output_dir, paste0("Fig14-Schoenfelds_residuals_score-",Sys.Date(),".png")),
    plot = plot[[1]],
    width = 10,
    height = 6,
    units = "in",
    dpi = 300
  )

Mortality

Fig15-Score_mortality_spline WILSON

library(binom)

# Assuming df_LGE is your dataframe
data <- df_LGE %>%
  droplevels() %>%
  mutate(
    event = outcome_death,
    time = outcome_FU_time_death
  )

# Summarizing data and calculating Wilson score intervals
D <- data %>%
  group_by(score) %>%
  summarise(
    n = n(),
    events_sum = sum(event),  # Sum of events per group
    mortality = events_sum / n,  # Proportion of events
    survival = 1 - mortality,
    std_error = sd(event, na.rm = TRUE) / sqrt(n),  # Standard error of event proportion
    col = unique(score_categ)
  ) %>%
  mutate(
    wilson = binom.confint(events_sum, n, methods = "wilson", conf.level = 0.995)  # Calculating Wilson score intervals
  )

# Extracting lower and upper bounds from Wilson score
D <- D %>%
  mutate(
    lower_95 = wilson[, "lower"],
    upper_95 = wilson[, "upper"]
  )

# For the graphics
D[16:17, "upper_95"] <- 1.01

# Continue with your existing plotting code
color_palette <- c("1_low_risk" = "green4", "2_medium_risk" = "orange2", "3_high_risk" = "red4")
max_n <- max(D$n)
scale_factor <- max_n / max(D$mortality, na.rm = TRUE)

# Smooth predictions and confidence intervals using loess model
D$smooth_pred <- predict(loess(mortality * max_n ~ score, data = D), se = FALSE)
D$smooth_lower <- predict(loess(lower_95 * max_n ~ score, data = D), se = FALSE)
D$smooth_upper <- predict(loess(upper_95 * max_n ~ score, data = D), se = FALSE)

# Base plot with mortality predictions
gggraph <- ggplot(D, aes(x = score, y = mortality * max_n)) +
  geom_bar(stat = "identity", aes(y = n, fill = col), position = position_dodge(), width = 0.9) +
  scale_fill_manual(values = color_palette) +
  geom_ribbon(aes(ymin = smooth_lower, ymax = smooth_upper), fill = "#F37B59", alpha = 1) +
  geom_line(aes(y = smooth_pred), color = "red", size = 1.5) +
  scale_y_continuous(
    name = "Frequency (N)",
    sec.axis = sec_axis(~ . / max(D$n), name = "All-cause mortality rate (%)"),
    limits = c(-0.1 * max_n, 1.3 * max_n)
  ) +
  labs(
    title = "The CMR-LGE score (N=3,591)",
    x = "CMR-LGE score",
    y = "Frequency (N)"
  ) +
  xlim(0, max(D$score)) +
  scale_x_continuous(breaks = 1:17) +
  theme_classic(base_size = 14) +
  theme(
    plot.background = element_rect(fill = "white", color = NA),
    panel.background = element_rect(fill = "white", color = NA),
    legend.position = "none",
    axis.line = element_line(color = "black"),
    axis.text = element_text(color = "black"),
    axis.title = element_text(color = "black")
  )

# Print the plot
print(gggraph)

# Save the plot in a folder
ggsave(
  filename = here(figures_output_dir, paste0("Fig15-Score_mortality_spline", Sys.Date(),".png")),
  plot = gggraph, width = 9, height = 6, units = "in", dpi = 600)

Tab25-Mortality prediction at 5 and 10 years (w/bootstrap)

library(survival)
library(dplyr)
library(purrr)  # for the map functions
library(kableExtra)

# Main analysis
n_bootstrap <- 100
time.choosen <- 10*12  # Predicting at 5 and 10 years

# Assuming df_LGE is your dataframe
data <- df_LGE %>%
  droplevels() %>%
  mutate(
    event = outcome_death,
    time = outcome_FU_time_death
  )

# Function to process data for survival analysis
process_data <- function(data, event_name, time_name, time_threshold) {
  data$event_time <- ifelse(data[[event_name]] == 1 & data[[time_name]] < time_threshold, 1,
                            ifelse(data[[time_name]] >= time_threshold, 0, NA))
  data <- filter(data, !is.na(event_time))
  return(data)
}

# Preprocess the dataset
data_processed <- process_data(data, event_name = "event", time_name = "time", time_threshold = time.choosen)


# Fitting a Cox model
model.cox <- coxph(Surv(time, event_time) ~ score, data = data_processed, x = TRUE)

# Function to generate predictions for bootstrap samples
predictions_function <- function(data, model, times) {
  indices <- sample(1:nrow(data), replace = TRUE)
  bootstrap_sample <- data[indices, ]
  predictions <- 1 - predictSurvProb(model, newdata = bootstrap_sample, times = c(times))
  # Return a dataframe with predictions and the associated scores
  data.frame(score = bootstrap_sample$score, predictions = predictions)
}

# Assuming `data_processed` is your pre-processed dataset and `model.cox` is your fitted Cox model
n_bootstrap <- 100  # Number of bootstrap samples
time.choosen <- 5 * 12  # Predicting at 5 years, can add more times if needed
# Apply bootstrap to calculate predictions for each iteration
bootstrap_results <- purrr::map(1:n_bootstrap, ~predictions_function(data_processed, model.cox, time.choosen))
# Combine all bootstrap results into a single dataframe
bootstrap_data <- do.call(rbind, bootstrap_results)
# Group by score and summarize the predictions in a list or any other summary statistic
summary_data.5 <- bootstrap_data %>%
  group_by(score) %>%
  summarise(
    mean_predictions.5 = mean(predictions, na.rm = TRUE)
  )


# Assuming `data_processed` is your pre-processed dataset and `model.cox` is your fitted Cox model
n_bootstrap <- 100  # Number of bootstrap samples
time.choosen <- 10 * 12  # Predicting at 5 years, can add more times if needed
# Apply bootstrap to calculate predictions for each iteration
bootstrap_results <- purrr::map(1:n_bootstrap, ~predictions_function(data_processed, model.cox, time.choosen))
# Combine all bootstrap results into a single dataframe
bootstrap_data <- do.call(rbind, bootstrap_results)
# Group by score and summarize the predictions in a list or any other summary statistic
summary_data.10 <- bootstrap_data %>%
  group_by(score) %>%
  summarise(
    mean_predictions.10 = mean(predictions, na.rm = TRUE)
  )

summary_data <- cbind(summary_data.5, summary_data.10)
df_data <- summary_data[,c(1,2,4)]
df_data
##    score mean_predictions.5 mean_predictions.10
## 1      1        0.009828916          0.02497375
## 2      2        0.013158908          0.03334758
## 3      3        0.017607013          0.04446451
## 4      4        0.023540680          0.05917241
## 5      5        0.031441791          0.07854167
## 6      6        0.041937296          0.10389230
## 7      7        0.055833964          0.13679737
## 8      8        0.074154173          0.17903594
## 9      9        0.098165683          0.23245372
## 10    10        0.129391645          0.29867435
## 11    11        0.169576689          0.37860040
## 12    12        0.220570562          0.47167573
## 13    13        0.284075033          0.57499272
## 14    14        0.361191961          0.68255994
## 15    15        0.451732703          0.78536305
## 16    16        0.553340864          0.87300586
## 17    17        0.660686345          0.93717522
write.csv(df_data, file = "outputs/csv_files/pred_by_score.csv")


# export in html
knitr::kable(df_data, caption = "Prediction by the score (Tab25)", format = "html") %>%
  kableExtra::kable_styling(full_width = F, bootstrap_options = c("striped", "hover", "condensed", "bordered"))
Prediction by the score (Tab25)
score mean_predictions.5 mean_predictions.10
1 0.0098289 0.0249738
2 0.0131589 0.0333476
3 0.0176070 0.0444645
4 0.0235407 0.0591724
5 0.0314418 0.0785417
6 0.0419373 0.1038923
7 0.0558340 0.1367974
8 0.0741542 0.1790359
9 0.0981657 0.2324537
10 0.1293916 0.2986743
11 0.1695767 0.3786004
12 0.2205706 0.4716757
13 0.2840750 0.5749927
14 0.3611920 0.6825599
15 0.4517327 0.7853630
16 0.5533409 0.8730059
17 0.6606863 0.9371752
# Export in word
ft <- flextable(df_data)
ft <- set_table_properties(ft, layout = "autofit")
doc <- read_docx() %>%
  body_add_par("Prediction by the score (Tab25)", style = "heading 1") %>%
  body_add_flextable(ft)

print(doc, target = here(tables_output_dir,paste0("Tab25-Predictions_Score-",Sys.Date(), ".docx")))

Fig16-Score_mortality_stacked

data <- df_LGE %>% 
  droplevels() %>% mutate(
        event = outcome_death,
        time = outcome_FU_time_death
      )


# Assuming df contains your data and D contains the summarized results
D <- data %>%
  group_by(score) %>%
  summarise(
    n = n(),
    events_sum = sum(event),  # Sum of events per group
    mortality = events_sum / n,  # Proportion of events
    survival = 1-mortality,
    std_error = sd(event) / sqrt(n),  # Standard error of event proportion
    lower_95 = mortality - 1.96 * std_error,
    upper_95 = mortality + 1.96 * std_error,
    col = unique(score_categ)
  ) 

color_palette <- c("1_low_risk" = "green4", "2_medium_risk" = "orange2", "3_high_risk" = "red4")

# the dataframe
D <- as.data.frame(D)

# Reshape the data for plotting
df_long <- D  %>%
  pivot_longer(cols = c("mortality", "survival"), names_to = "outcome", values_to = "proportion")

# Creating the 100% stacked bar plot
g <- ggplot(df_long, aes(x = factor(score), y = proportion, fill = outcome)) +
  geom_bar(stat = "identity", position = "fill") +
  scale_y_continuous(labels = scales::percent_format()) +
  labs(x = "Score", y = "Proportion of Outcome", fill = "Outcome") +
  theme_classic() +
  scale_fill_manual(values = c("mortality" = "red", "survival" = "green4")) # Customize colors as needed

g

ggsave(
  filename = here(figures_output_dir, paste0("Fig16-Score_mortality_stacked-", Sys.Date(),"_plot.png")),
  plot = g, width = 9, height = 6, units = "in", dpi = 600)

Function for AUC and PRAUC (to add)

Fig17-Score_AUC10

# data <- df_LGE %>% 
#   droplevels() 
# 
# results.score.10 <- CoxPredictScore(
#   derivation = data, 
#   validation = data, 
#   time.name = "outcome_FU_time_death", 
#   times = 10*12,
#   event.name ="outcome_death", 
#   variable = "score",
#   n_bootstrap = 100, 
#   ci_level = 0.995, 
#   seed = 123)
# 
# 
# # CREATING AUC CURVES
# roclist <- list(results.score.10$roc_derivation$roc_obj)
# 
# names(roclist) <- c(paste0("AUC Score - ", results.score.10$derivation$auc ))
# 
# library(pROC)
# # GRAPHCIS - AUC (Solenn)
# g <- ggroc(roclist, aes = "colour", legacy.axes = TRUE) + geom_line(size = 0.8) +
#   theme_classic()+
#   ggtitle("AUC 10 years") +
#   labs(x = "1 - Specificity",
#        y = "Sensitivity") +
#   theme_minimal() +
#   theme(
#     plot.title = element_text(size = 14, hjust = 0.5),
#     plot.subtitle = element_text(size = 12, hjust = 0.5),
#     axis.line = element_line(color = "black"),
#     panel.grid.major = element_blank(),
#     panel.grid.minor = element_blank(),
#     axis.text.x = element_text(size = 14),  # Increase size of X axis labels
#     axis.text.y = element_text(size = 14),  # Increase size of Y axis labels
#     axis.title.x = element_text(size = 16),  # Increase size of X axis title
#     axis.title.y = element_text(size = 16),  # Increase size of Y axis title
#     legend.text = element_text(size=14),
#     legend.position = c(0.95, 0.05),  # Adjust the position within the graph (x, y)
#     legend.justification = c(1, 0),  # Set the justification to bottom-right
#     legend.box.just = "right",  # Set the legend box justification to right
#     legend.title = element_blank(),  # Remove legend title
#     legend.box.background = element_rect(color = "black", fill = NA)) +  # Add black border
# 
#   scale_colour_manual(values = c( "red"))
# 
# 
# # Add the y = x line (line of equality)
# g <- g + geom_abline(intercept = 0, slope = 1, linetype = "dashed", color = "black")
# 
# g
# 
# ggsave(
#   filename = here(figures_output_dir, paste0("Fig17-Score_AUC10-", Sys.Date(),".png")),
#   plot = g, width = 9, height = 6, units = "in", dpi = 600)

Fig18-Score_PRAUC10

# data <- df_LGE %>% 
#   droplevels() 
# 
# results.score.10 <- CoxPredictScore(
#   derivation = data, 
#   validation = data, 
#   time.name = "outcome_FU_time_death", 
#   times = 10*12,
#   event.name ="outcome_death", 
#   variable = "score",
#   n_bootstrap = 100, 
#   ci_level = 0.995, 
#   seed = 123)
# 
# perc_death <- 379/1790
# 
# 
# g <- ggplot() +
#   geom_line(data = results.score.10$roc_derivation$coords, aes(x = recall, y = precision, color = "A_Score")) + 
#   geom_hline(yintercept = perc_death, color = "black", linetype = "dashed") + 
#   labs(
#     x = "Recall",
#     y = "Precision",
#     title = "PRAUC 10",
#     color = "Dataset"
#   ) +
#   scale_color_manual(
#     values = c("A_Score" = "red"),
#     labels = c(paste("Cox Score - ", results.score.10$derivation$prauc)))+
#   theme_classic () +
#   theme(
#     plot.title = element_text(size = 14, hjust = 0.5),
#     plot.subtitle = element_text(size = 12, hjust = 0.5),
#     axis.line = element_line(color = "black"),
#     panel.grid.major = element_blank(),
#     panel.grid.minor = element_blank(),
#     axis.text.x = element_text(size = 14),  # Increase size of X axis labels
#     axis.text.y = element_text(size = 14),  # Increase size of Y axis labels
#     axis.title.x = element_text(size = 16),  # Increase size of X axis title
#     axis.title.y = element_text(size = 16),  # Increase size of Y axis title
#     legend.text = element_text(size=14),
#     legend.position = c(0.9, 0.05),
#     legend.justification = c(1, 0),
#     legend.box.just = "right",  # Set the legend box justification to right
#     legend.title = element_blank(),  # Remove legend title
#     legend.box.background = element_rect(color = "black", fill = NA),
#     plot.margin = margin(20, 20, 20, 20), 
#     plot.background = element_rect(fill = "white", color = "white", size = 1)) +  # Add a white background
# 
#     scale_y_continuous(limits = c(0, 1))  # Set y-axis limits to 0 and 1
# 
# g
# 
# ggsave(
#   filename = here(figures_output_dir, paste0("Fig18-Score_PRAUC10-", Sys.Date(),".png")),
#   plot = g, width = 6, height = 6, units = "in", dpi = 600)

Fig19-LGE-KM-score-death

df_selected <- df_LGE %>% mutate(
  event = outcome_death,
  time = outcome_FU_time_death
)

# Data parameters
results <- createSurvivalPlot(
  data = df_LGE,
  compared_with = "score_categ",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  my_colors =  c("green4","orange2","red4"),
  my_legends = c("Low","Medium", "High"),
  confint_choosen = 0.995,
  mytitle = c("Fig19-LGE-KM-score-death")
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ score_categ"
results$HR
##                                            HR_CI p_value
## score_categ2_medium_risk   9.08 ( 5.98 - 13.78 )  <0.001
## score_categ3_high_risk   31.39 ( 22.14 - 44.49 )  <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig19-LGE-KM-score-death_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig19-LGE-KM-score-death_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

Fig20-LGE-KM-score-MACE

###### UNIVARIATE
df_selected <- df_MACE %>% mutate(
  event = outcome_MACE,
  time = time.censored # method of censoring when poatients die from another cause. 
)


# Data parameters
results <- createSurvivalPlot(
  data = df_selected,
  compared_with = "score_categ",
  time = "outcome_FU_time_death",
  event = "outcome_death",
  my_colors =  c("green4","orange2","red4"),
  my_legends = c("Low","Medium", "High"),
  confint_choosen = 0.995,
  mytitle = c("Fig20-LGE-KM-score-MACE")
)
## [1] "Cox model formula: Surv(outcome_FU_time_death/12, outcome_death) ~ score_categ"
results$HR
##                                            HR_CI p_value
## score_categ2_medium_risk   7.35 ( 3.68 - 14.66 )  <0.001
## score_categ3_high_risk   25.55 ( 16.27 - 40.12 )  <0.001
results$ggsurv

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig20-LGE-KM-score-MACE_plot-", Sys.Date(),".png")),
  plot = results$ggsurv$plot, width = 10, height = 6, units = "in", dpi = 600)
ggsave(
  filename = here(figures_output_dir,paste0("Fig20-LGE-KM-score-MACE_risk-", Sys.Date(),".png")),
  plot = results$ggsurv$table, width = 10, height = 3, units = "in", dpi = 600)

Other figures

Fig21-Csv_ARP_plot

exported in csv to build the graphics on excell

# 1] extent
py <- pyears(Surv(outcome_FU_time_death*(365/12), outcome_death) ~ CMR_LGE_ischemic_extent_categ, data = df_LGE, data.frame = T)
df_ext<<- py$data
colnames(df_ext)[1] <- "subgroups"
df_ext$group <- "B_Ext"
df_ext$annual_rates <- round(100*(df_ext$event/df_ext$pyears), 1) # Ca fait du 100 personnes années

# 2] TRANSMURALITY
py <- pyears(Surv(outcome_FU_time_death*(365/12), outcome_death) ~ CMR_LGE_ischemic_transmurality, data = df_LGE, data.frame = T)
df_transm<<- py$data
colnames(df_transm)[1] <- "subgroups"
df_transm$group <- "C_Transm"
df_transm$annual_rates <- round(100*(df_transm$event/df_transm$pyears), 1) # Ca fait du 100 personnes années

# 3] MULTIPLE
py <- pyears(Surv(outcome_FU_time_death*(365/12), outcome_death) ~ CMR_LGE_ischemic_multiple, data = df_LGE, data.frame = T)
df_multi<<- py$data
colnames(df_multi)[1] <- "subgroups"
df_multi[1,1] <- "A_Focal"
df_multi[2,1] <- "B_Multi"
df_multi$group <- "D_Multiple"
df_multi$annual_rates <- round(100*(df_multi$event/df_multi$pyears), 1) # Ca fait du 100 personnes années

# 4] SEPTAL
py <- pyears(Surv(outcome_FU_time_death*(365/12), outcome_death) ~ CMR_LGE_ischemic_location_4, data = df_LGE, data.frame = T)
df_septal <- py$data
colnames(df_septal)[1] <- "subgroups"
df_septal[1,1] <- "A_No_septal"
df_septal[2,1] <- "B_Anterior"
df_septal[3,1] <- "C_Septal"
df_septal$group <- "E_localization"
df_septal$annual_rates <- round(100*(df_septal$event/df_septal$pyears), 1) # Ca fait du 100 personnes années

# 5] MIDWALL
py <- pyears(Surv(outcome_FU_time_death*(365/12), outcome_death) ~ CMR_LGE_midwall_presence, data = df_LGE, data.frame = T)
df_mid<<- py$data
colnames(df_mid)[1] <- "subgroups"
df_mid[1,1] <- "A_No_midwall_ass"
df_mid[2,1] <- "B_Midwall_ass"
df_mid$group <- "F_Midwall"
df_mid
##   subgroups    pyears    n event     group
## 1      <NA> 28911.364 3237   418 F_Midwall
## 2      <NA>  2923.997  354   131 F_Midwall
df_mid$annual_rates <- round(100*(df_mid$event/df_mid$pyears), 1) # Ca fait du 100 personnes années

# GLOBAL DF
df_global <- rbind(df_ext, df_transm, df_multi, df_septal ,df_mid) #df_normal
df_global <- df_global %>% mutate(subgroups = paste(as.character(group), "~", subgroups,sep=""))


# Create the grouped barplot using ggplot2
library(ggplot2)

# Create the plot
gg_graph <- ggplot(df_global, aes(x = group, y = annual_rates, fill = subgroups, label = annual_rates)) +
  geom_bar(position = "dodge", stat = "identity", just = 1, width = 0.7) +  # Equal-width bars
  scale_fill_manual(values = adjustcolor(c("#4292C6","#D52B2B","#2C3E50","#4292C6","#D52B2B","#2C3E50", "#D52B2B", "#2C3E50","#4292C6","#D52B2B","#2C3E50","#D52B2B","#2C3E50"), alpha.f = 0.8)) +  # Set custom colors
  labs(title = "Grouped Barplot with Subgroups",
       x = "group",  # X-axis label
       y = "Annual Rates",     # Y-axis label
       fill = "subgroups") +   # Legend title
  geom_text(
    aes(x = group, y = annual_rates, label = sprintf("%.1f", annual_rates), group = subgroups),
    position = position_dodge(width = 1),
    vjust = 0, size = 4, fontface = "bold") +
  scale_y_continuous(expand = c(0, 1), limits = c(0,15), breaks = seq(0, 17.5, 2.5)) +
  theme_bw()+
  theme(
    panel.grid.major = element_line(color = "gray", size = 0.2, linetype = "dotted"),
    panel.grid.minor = element_line(color = "gray", size = 0.2, linetype = "dotted"),
    plot.title = element_text(hjust = 0.5),
    axis.title.x = element_blank(),
    # axis.text.x = element_blank(), to remove the x axis legend
    axis.line.x = element_blank(),
    axis.ticks.x = element_blank(),
    axis.text.y = element_text(size = 12, face = "bold"),
    panel.border = element_blank(),
    legend.position = "none",  # Move the legend to the top-left corner
    legend.justification = c(0, 1),  # Anchor the legend to the top-left corner
    legend.text = element_text(size = 12),  # Adjust the legend text size
    legend.title = element_text(size = 14)  # Adjust the legend title size
  )
gg_graph <- gg_graph + coord_flip()

plot.new()
print(gg_graph,newpage = FALSE)

# finaly details done using excell
write.csv(df_global, file = here(figures_output_dir,"Fig21-annualized_death_rate.csv"))


# Compare subgroups
print(df_global) # u see the dataframe used to build the graph
##                        subgroups    pyears    n event          group
## 1           B_Ext~B_1_2_segments 12538.579 1392    23          B_Ext
## 2           B_Ext~C_3_5_segments 17452.546 1953   294          B_Ext
## 3         B_Ext~D_more6_segments  1844.237  246   232          B_Ext
## 4  C_Transm~B_Subendocardial<50% 15267.793 1698    79       C_Transm
## 5  C_Transm~C_Subendocardial≥50% 13756.994 1549   259       C_Transm
## 6          C_Transm~D_Transmural  2810.575  344   211       C_Transm
## 7                  D_Multiple~NA 28906.618 3226   319     D_Multiple
## 8                  D_Multiple~NA  2928.744  365   230     D_Multiple
## 9              E_localization~NA 24220.411 2662    99 E_localization
## 10             E_localization~NA  3632.179  422   105 E_localization
## 11             E_localization~NA  3982.772  507   345 E_localization
## 12                  F_Midwall~NA 28911.364 3237   418      F_Midwall
## 13                  F_Midwall~NA  2923.997  354   131      F_Midwall
##    annual_rates
## 1           0.2
## 2           1.7
## 3          12.6
## 4           0.5
## 5           1.9
## 6           7.5
## 7           1.1
## 8           7.9
## 9           0.4
## 10          2.9
## 11          8.7
## 12          1.4
## 13          4.5
n = 1 # now i want to compare by 2 therefore i use this method

rate_comp <- ratedifference(df_global$event[n + 1], df_global$event[n], df_global$pyears[n + 1], df_global$pyears[n], CRC = TRUE, conf.level = 0.995)
##                  Cases  Person-time Incidence rates     Lower CL     Upper CL
## Exposed   2.940000e+02 1.745255e+04    1.684568e-02 1.408788e-02 1.960348e-02
## Unexposed 2.300000e+01 1.253858e+04    1.834339e-03 7.606874e-04 2.907990e-03
## Total     3.170000e+02 2.999112e+04    1.056979e-02 8.903373e-03 1.223621e-02
value <- as.character(df_global$p.value)
result <- ifelse(df_global$p.value < 0.001 | df_global$p.value == 0, "<0.001", value)
print(result)
## logical(0)

Fig22-LGE-Forestplot

library(forestplot)
# function
df_selected <- df_all %>%
  mutate(
    demo_age_categ = factor(case_when(
      demo_age < 65 ~ "age<65",
      TRUE ~ "age≥65"
    ), levels = c("age<65", "age≥65")),
    CMR_LVEF_categ = factor(ifelse(
      CMR_LVEF <= 40, "HFrEF", "HFmrEF"
    ), levels = c("HFrEF", "HFmrEF"))
  )

print("Forest plot")
## [1] "Forest plot"
D <- forest_function(
  df = df_selected, 
  time_var = "outcome_FU_time_death",
  event_var = "outcome_death",
  var_of_interest = "CMR_LGE_ischemic_presence",
  "demo_age_categ",
  "demo_gender",
  "CV_risk_obesity",
  "CV_risk_diabete",
  "CV_risk_HTA",
  "CV_risk_Smoking",
  "clini_NYHA",
  "CMR_LVEF_categ"
)

base_data <- D

name_row_vector <- c("Age","<65 years", "≥65 years", "Gender","Female", "Male", "Body Mass Index ","No obesity", "Obesity", "Diabete mellitus", "No", "Yes", "Hypertension", "No", "Yes", "Smoking", "No", "Yes", "Symptoms", "Asymptomatic","Symptomatic", "LVEF","≤40%", ">40%")

base_data$name <- name_row_vector

# Generate the forestplot
forest_plot <- base_data |>
  forestplot(
    labeltext = c(name, ratio1, ratio2, OR, Pval, PValInter), 
    graph.pos = 4,
    mean = mean,
    upper = upper,
    lower = lower,
    is.summary = FALSE, # c(rep(TRUE, 2), rep(c(TRUE, FALSE, FALSE), 8)), #Make Text Bold to highlight Summary rows
    boxsize = 0.2,  # Adjust the boxsize as needed) 
    clip = c(0, 7),  #Lower and upper limits for clipping confidence intervals to arrows
    align = c("r", "c", "c", "r","l", "l"), # make it work 
    vertices = TRUE,
    
    xlog = FALSE,  #Log scale on X axis 
    
    col = fpColors(box = "royalblue",
                    line = "darkblue",
                    summary = "royalblue")) |>

  fp_set_zebra_style("#EFEFEF", ignore_subheaders = FALSE)|>

  fp_set_style(box = "red",
               line = "gray0",
               summary = "royalblue",
               align = "lrrr")

print(forest_plot)

Fig23-LGE-spline_curves

Encore des bug car HR de lui-même devrait être de 1 non ? Ref = 3

# Data
df_selected <- df_LGE

fit.cox = coxph(Surv(outcome_FU_time_death/12,outcome_death) ~ pspline(CMR_LGE_ischemic_extent_count), data = df_selected) # used median for 1 ...

## get predicted values for fitted spline
predicted = predict(fit.cox , type = "terms" , se.fit = TRUE , terms = 1, reference = "strata")


df_test <- data.frame(
  LGE_count = df_selected$CMR_LGE_ischemic_extent_count,
  HR = exp(predicted$fit),
  Upper_CI = exp(predicted$fit + 2.81 * predicted$se),
  Lower_CI = exp(predicted$fit - 2.81 * predicted$se)
  )

colnames(df_test) <- c("LGE_count","HR","Upper_CI","Lower_CI")

df_test <- as.data.frame(df_test)


# Plot using ggplot2
library(ggplot2)
gggraph <- ggplot(aes(x = LGE_count, y = HR), data=df_test) +
  geom_abline(slope = 0, intercept = 1, color = "black") +
  geom_vline(xintercept = 3, linetype = "dashed", size = 0.5, color = "black")+
  geom_smooth(method = "loess",color = "red", size = 0.7) +
  geom_ribbon(aes(ymin = predict(loess(Upper_CI ~ LGE_count, data = df_test)), 
                  ymax = predict(loess(Lower_CI ~ LGE_count, data = df_test))),
              fill = "orangered", alpha = 0.3) +
  
  labs(
    title = "Fig23-LGE-spline_curves",
    x = "Number of ischemic LGE segments",
    y = expression("Hazard Ratio for all-cause mortality n\ vs 3 segments of LGE (99.5% CI)")) +

  xlim(0, 8) +
  ylim(0, 40) +
  
  scale_y_continuous(breaks = c(1, 5, 10, 30)) +  # Y-axis marks at 1, 5, 10, 30
  scale_x_continuous(breaks = seq(0, 9, 1)) +  # X-axis marks every 1
  
  theme(
    panel.background = element_rect(fill = "white", color = NA),
    axis.line = element_line(color = "black"),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    axis.text.x = element_text(size = 16),  # Increase x-axis label font size
    axis.text.y = element_text(size = 16) 
  ) 
gggraph

# Save the plot in a folder 
ggsave(
  filename = here(figures_output_dir, paste0("Fig23-LGE-spline_curves-", Sys.Date(), ".png")), 
  plot = gggraph, width = 9, height = 6, units = "in", dpi = 600)